user562549
user562549

Reputation: 181

Need for a regex

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

Answers (1)

cmbuckley
cmbuckley

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

Related Questions