C++11 Regex Capture Groups By Name

Travis Parks picture Travis Parks · Jun 2, 2013 · Viewed 13.1k times · Source

I am converting my boost-based regular expressions to C++11 regex. I have a capture group called url:

\s*?=\s*?(("(?<url>.*?)")|('?<url>.*?)'))

With boost, if you had an smatch you could call match.str("url") to get the capture group by name. With std::smatch, I am only seeing indexed sub-matches.

How can I get access to the url capture using the std::smatch class?

Answer

aaronman picture aaronman · Jun 3, 2013

You cannot name a capture group with the c++11 standard. C++11 regex conforms to the ECMAScript syntax. Here is a link that explains it all http://www.cplusplus.com/reference/regex/ECMAScript/. Even though this maybe disappointing if you think about it a true regular expression will not support this it is extra.