简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM