makefun
makefun

Reputation: 133

Usage of regex in c++11

I'm using VS2010.

I have problem with regular expression

What regular expression should I use to search in string

std::string foo("s:{foo} s1:{bar}");

words foo, bar and possibly know they position.

I thought that something like

std::regex r("\\{.*\\}");

should work. But it doesn't. Why?

Upvotes: 0

Views: 135

Answers (1)

Anirudha
Anirudha

Reputation: 32787

for string s:{foo} s1:{bar}

{.*} would match {foo} s1:{bar}

.* matches greedily that is it would match till the last } in your case


{.*?} would match {foo} and in the next match it would match {bar}

.*? matches lazily that is it would match till the first } in your case

Upvotes: 1

Related Questions