C++11 Regex Capture Groups By Name
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.
Related videos on Youtube
Travis Parks
I'm a developer who spends most of his time writing business applications in .NET. I especially enjoy computing theory, application design and good programming practices. I try to keep my skills up-to-date and keep my knowledge broad. I love creating open source projects; check me out on GitHub. I consider myself an expert at .NET, software design, automation and large-scale distributed enterprise architectures.
Updated on September 15, 2022Comments
-
Travis Parks over 1 year
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 callmatch.str("url")
to get the capture group by name. Withstd::smatch
, I am only seeing indexed sub-matches.How can I get access to the url capture using the std::smatch class?
-
HamZa almost 11 yearsHave you tried
(?P<url>.*?)
instead of(?<url>.*?)
? -
Travis Parks almost 11 years@HamZa I am not sure if C++11 regex supports named capture groups. I just read the entire chapter dedicated to the topic in Stroustrup's new "The C++ Programming Language" and it doesn't even mention it. And many of the online references don't seem to indicate otherwise.
-
HamZa almost 11 yearsIt seems it doesn't support named groups according to this answer.
-
-
Travis Parks almost 11 yearsCan you post an example extracting a nested group? Perhaps where the match can be on either side of a pipe?
-
Travis Parks almost 11 yearsI basically want to see how to efficiently extract my url based on my posted example, updated to not rely on named capture groups.
-
Dilawar almost 3 yearsThis makes me sad!