The last assert always fails, because regex::match insists on including the space after the ":" in the second match result, which seems wrong to me. I've tried giving various different combinations of flags to the regex ctor, although from what I can tell from the documentation the default flags should work. This is with VC7 and boost 1.30.2. For comparison, perl (5.6.1) does not seem to have this problem, as the following script illustrates:
#!/usr/bin/perl print "matches: <$1> <$2>\n" if ('foo: bar' =~ /([\w]+):[\s]*(.*)/);
Is there any way to get the behavior I want?
This is the difference between perl and POSIX leftmost-longest matching rules showing itself (the next release will default to perl rules and do what you want, but of course that doesn't help you now), basically non-marked sections are neither greedy nor non-greedy under POSIX rules, so regex finds the match it does because it makes $2 further to the left than the alternative (without effecting the overall match). You can get the effect you want by making your expression more "precise": "([\\w]+):[\\s]*([^\\s].*)" for example, John. --------------------------------- Want to chat instantly with your online friends? Get the FREE Yahoo!Messenger
participants (1)
-
John Maddock