C++11 Regex Capture Groups By Name

≯℡__Kan透↙ 提交于 2019-12-04 17:43:19

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/16886992/c11-regex-capture-groups-by-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!