I have problem creating case less, global match and multi line regexes in boost and I'd like to ask for a few examples of equivalent (Javascript's RegEx <-> boost::regex) regex test
js: string.match( /^abc/ ) string.match( /^abc/i) string.match( /^abc/g) string.match( /^abc/m)
c++
First off remember that regex_match doesn't *search*, it succeeds only if the whole of the expression matches the whole of the text, so you really need to be using regex_search.
regex_match(string, regex("^abc"), match_default) regex_match(string, regex("^abc"), match_default | icase) // <- is it correct?
No, regex_search(whatever, regex("^abc", regex::perl|regex::icase));
regex_match(string, regex("^abc"), ?? ) //global match?
Use regex_iterator or regex_token_iterator to enumerate through several matches in one string.
regex_match(string, regex("^abc"), ?? ) //multi line?
Boost.Regex will always match ^ against embedded newlines.
also I'd like to ask what are the proper namespaces/typedefs/enums I have to use for match flags (for example, there's boost::regex_constants::icase and boost::regex::icase etc...)
Those nested within boost::regex are for use with the regex constructor, and determine the regular expression syntax, and case sensitivity. Those that are of type boost::regex_constants::match_flag_type are for passing to regex_match/regex_search/regex_iterator etc. Finally in the next release, the Perl-like (?imsx-imsx) syntax will be supported, which makes all this a little easier... John.