Reputation: 181
I need a regex to get MyName ( MyName may contain any character except " ) from this string:
lablabla name="MyName" user="MyUser" lablabla
I used:
boost::regex reg(".*name=\"(?<action>.*)\"\\s.*", boost::regex::perl);
but it returns:
MyName" user="MyUser
Upvotes: 1
Views: 45
Reputation: 42547
How about:
boost::regex reg(".*name=\"(?<action>.*?)\"\\s.*", boost::regex::perl);
which makes it ungreedy; or:
boost::regex reg(".*name=\"(?<action>[^\"]*)\"\\s.*", boost::regex::perl);
which explicitly specifies that the action cannot contain double quotes.
Upvotes: 3