使用命名捕获可以找出给定正则表达式中命名组的所有名称
Use named capturing to find out all names of named groups in a given regular expression
我想知道在给定的正则表达式中是否有一个命名捕获组,所以我将使用命名捕获来找出该表达式中的所有名称。
请参阅以下代码片段:
std::string expr = "(?<ns>\S+)"; // (?<ns>S+)
boost::regex re("\(\?\<(?<name>.+)\>"); // (?<(?<name>.+)>
bool found = boost::regex_search(expr, re); // **found is always false**
我还尝试使用以下两个在线regex测试人员进行验证,他们都工作并找到了"ns"。
- https://regex101.com
- http://www.regexplanet.com/advanced/perl/index.html
为什么我的代码不起作用?我是否滥用了boost::regex?
我使用的C++Boost库的版本是1.59
您不应该转义<
和>
。试试这个:
"\(\?<(?<name>.+)>"
相关文章:
- 有没有办法将不连续的捕获组组合到单个正则表达式中?
- 使用 boost::regex 从目录中获取带有一些正则表达式的文件名称时出现意外输出
- 正则表达式,包含名称 + "string" + 数字,没有其他内容
- 有没有办法在C++正则表达式中重用模式的一部分?
- 有条件地忽略 c++11 正则表达式中的大小写
- 这种使用增强正则表达式库有什么问题
- regex_error。我的正则表达式有什么问题
- 有效文件夹名称C (Windows)的正则表达式
- 是否可以在正则表达式中命名子图案,然后通过C 中的子图案名称提取匹配
- gcc 4.8或更早版本对正则表达式有问题吗
- "~"标记在 Perl 正则表达式中有什么用?
- 与其他跨平台正则表达式库相比,Oniguruma 有多好
- 有没有办法在一次迭代中进行任意数量的正则表达式替换
- 觉得有必要改进我的正则表达式
- 使用命名捕获可以找出给定正则表达式中命名组的所有名称
- VS10 中文件名的正则表达式格式有什么问题<regex>?
- 如何使用正则表达式提取文本中的所有名称
- 是否有任何C/ c++编辑器支持替换正则表达式?
- 我的正则表达式代码有什么问题?
- CMake 正则表达式匹配包含声明中的标头名称