Regex failure when matching with a POSIX extended regexp

Hi folks, The following code demonstrates the problem I'm having. I'm using Boost 1.33.1 (Debian), but IIRC this worked last year with the same version because I tested it; possibly a Debian-specific regression? I expect both regular expressions here to match with the value string. They certainly to with egrep. However, I only get the second to match: % g++ -c regex.cc -o regex.o && g++ -o regex regex.o -lboost_regex % ./regex It didn't match the first It matched the second Am I correct in my expectation that expression1 will match? If not, what should I be doing to make it match? Many thanks, Roger -- .''`. Roger Leigh : :' : Debian GNU/Linux http://people.debian.org/~rleigh/ `. `' Printing on GNU/Linux? http://gutenprint.sourceforge.net/ `- GPG Public Key: 0x25BFB848 Please GPG sign your mail.

Roger Leigh wrote:
Hi folks,
The following code demonstrates the problem I'm having. I'm using Boost 1.33.1 (Debian), but IIRC this worked last year with the same version because I tested it; possibly a Debian-specific regression?
I expect both regular expressions here to match with the value string. They certainly to with egrep. However, I only get the second to match:
% g++ -c regex.cc -o regex.o && g++ -o regex regex.o -lboost_regex % ./regex It didn't match the first It matched the second
Am I correct in my expectation that expression1 will match? If not, what should I be doing to make it match?
Use regex_search. regex_match will only succeed if the expression matches *all* of the string, regex_search will *find* a sub-string that matches. John.

"John Maddock"
Roger Leigh wrote:
I expect both regular expressions here to match with the value string. They certainly to with egrep. However, I only get the second to match:
Am I correct in my expectation that expression1 will match? If not, what should I be doing to make it match?
Use regex_search. regex_match will only succeed if the expression matches *all* of the string, regex_search will *find* a sub-string that matches.
Ah, that's just what I needed. It works perfectly. Thank you all for your help! Regards, Roger -- .''`. Roger Leigh : :' : Debian GNU/Linux http://people.debian.org/~rleigh/ `. `' Printing on GNU/Linux? http://gutenprint.sourceforge.net/ `- GPG Public Key: 0x25BFB848 Please GPG sign your mail.

"John Maddock"
Use regex_search. regex_match will only succeed if the expression matches *all* of the string, regex_search will *find* a sub-string that matches.
Just to clarify this point. Does this mean that regex_match effectively puts ^ and $ on either side of my regex, to ensure it matches the whole string, whereas regex_search does not? Many thanks, Roger -- .''`. Roger Leigh : :' : Debian GNU/Linux http://people.debian.org/~rleigh/ `. `' Printing on GNU/Linux? http://gutenprint.sourceforge.net/ `- GPG Public Key: 0x25BFB848 Please GPG sign your mail.

Yes, regex_match effectively puts \A and \z on either end of the expression. John.

Roger Leigh
I expect both regular expressions here to match with the value string.
The result of regex_match is true only if the expression matches the whole of the input sequence. If you want to search for an expression somewhere within the sequence then use regex_search. If you want to match a prefix of the character string then use regex_search with the flag match_continuous set. -- Pete Forman -./\.- Disclaimer: This post is originated WesternGeco -./\.- by myself and does not represent pete.forman@westerngeco.com -./\.- the opinion of Schlumberger or http://petef.port5.com -./\.- WesternGeco.
participants (3)
-
John Maddock
-
Pete Forman
-
Roger Leigh