returns true or "\"" -> returns true or "this is -6ren">
gpt4 book ai didi

c++ - boost::regex_match 给出的结果与许多在线正则表达式测试器不同

转载 作者:行者123 更新时间:2023-11-28 07:18:45 30 4
gpt4 key购买 nike

我想匹配输入字段中给定的字符串。

A sample data could be "hello" -> returns true 
or "\"" -> returns true
or "this is a string" -> returns true
but """ should not be recognized as a string and should return false when checked by the regexp.

我正在初始化一个 boost 正则表达式解析器,如下所示:

    std::string myString = "\"\"\"";
boost::smatch match;
boost::regex regExpString3("[\"']((:?[^\"']|\\\")+?)[\"']");
bool statusString3 = boost::regex_match(myString, match, regExpString3);

regex_match 不应该匹配,但不幸的是它确实匹配......

我检查了几个在线正则表达式测试器:我的正则表达式不匹配(如预期的那样)。

不知道这可能是 boost 的错误还是我做错了什么?

Debuggex Demo: Click me to verify ("[\"']((:?[^\"']|\\")+?)[\"']"

谢谢

最佳答案

试试下面的表达式:

([\\"'])(?:[^\\"]|\\\\")+\\1

Regex101 Demo

关于c++ - boost::regex_match 给出的结果与许多在线正则表达式测试器不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19837845/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com