我的 XML 标签正则表达式不起作用
my Regex for xml tags is not working
regex starttag("(.*)<w*>");
regex endtag("(.*)</w*>");
regex taganddata(".*<w*>w*</w*>");
这就是我所拥有的,但在尝试匹配时它不起作用,我不知道为什么。
this is a start tag: " <House>"
this is a end tag: " </House>"
This is a data tag: " <City>Allentown</City>"
此外,要匹配的字符串是 xml 文件的一行(因此它在缩进的开头有空格(,因为我正在逐行进行。
我使用了正则表达式和其他服务,看起来它在那里匹配,但不在我的使用 regex stl 的 c++ 程序中
这是不起作用的
if (regex_match(line, starttag))
{
cout << "Start tag" << endl;
}
if (regex_match(line, endtag))
{
cout << "End tag" << endl;
}
if (regex_match(line, taganddata))
{
cout << "Data and Tags" << endl;
}
您的正则表达式需要正确转义。 即正斜杠需要正确转义
regex starttag("(.*)<\w*>");
regex endtag("(.*)<\/\w*>");
regex taganddata(".*<\w*>\w*<\/\w*>");
或者,您可以使用原始字符串格式:
regex starttag(R"((.*)<w*>)");
regex endtag(R"((.*)</w*>)");
regex taganddata(R"(.*<w*>w*</w*>)");
相关文章:
- FindPackageHandleStandardArgs.cmake:137 的 CMake 错误(消息):找不到 Boost (缺少:正则表达式)(找到合适的版本"1.72.0",
- 为什么在 while 循环中返回表达式不起作用
- 组合正则表达式部分使用 | 不起作用的 C++
- 如果检查不起作用,则 C++
- (C++) 确定不匹配的正则表达式捕获组
- 为什么正则表达式在 Java 中运行良好,但在 C++ 中不起作用
- 正则表达式C++不起作用
- Qt 中的不匹配数字正则表达式
- 我的 XML 标签正则表达式不起作用
- 若该语句不起作用,则该语句为真
- 不需要的正则表达式捕获
- 正则表达式 stl 不起作用
- 正则表达式迭代器在Cpp中不起作用
- 找不到c++正则表达式搜索模式
- 异常处理+多态性,如果异常方法在同一类中不起作用,则不起作用
- 我的最后一个正则表达式不起作用,但我无法弄清楚原因
- C++ 2011 std::正则表达式根本不起作用
- 使用正则表达式和 sed 命令替换C++代码中的' *'指针不起作用
- 无法弄清楚为什么正则表达式不起作用
- 正则表达式替换文件扩展名前缀放置不起作用 - 替换匹配项