I'm just starting into regular expressions in C++ and I've noticed a couple problems. I spent 20+ years using them in perl so there are certain things I "just expect". And I'm not finding them.
Specifically, I expect a regex to have a "multiline" mode where it will match beyond the first newline included in the target string. I can't find one.
Similarly, I have found that no search will proceed past a null character in the buffer either (possible with std::strings).
As a more minor complaint (because there is a workaround) I don't find a case-insensitive mode either. Am I missing something?
BTW the reason these things matter is I'm about to write a file searching utility that wants to be able to use regexes. If I can't solve the problem I will have to break the string into pieces at newlines or nulls and search the pieces individually. Ugh.
Not exactly the perl approach, but it'll work. In perl you do it with modifiers as you apply the regex, e.g. if ($x =~ /foo/i) { dosomething(); } would get you case-insensitive.
A difference here is that perl has "unnamed literal constant", where C++ prefers to create "named object". Both have the regular expression and modifier (flags).
The literal constant is used directly in match expression, while the named regex can be used in multiple expressions.
Use of unnamed temporary is possible too:
1 2
if ( std::regex_match( x, std::regex("foo", icase) ))
{ dosomething(); }
So the real difference is that perl has binary operator =~ but C++ uses function regex_match()
Keskiverto: yes, I don't find the C++ syntax problematic, except where it doesn't seem to work (see above). The perl syntax is nicely terse but without storing a regex in a var (which works fine) you can't otherwise reuse one. E.g. if ($x =~ /$regex/) { dosomething(); }