pcre \Q 和 \E 匹配错误
pcre \Q and \E match error
string sContent="the path is e:\develop\East\parser(delay)";
string path="e:\develop\East\parser(delay)";
char sRegex[128]; sprintf(sRegex, "\Q%s\E", src_str);
pcrecpp::RE(sRegex).PartialMatch(sContent);
不匹配,导致"\East" will abort '\Q'
。我该如何解决这个错误?
是的,这就是 \Q
..\E
功能的问题。
您可以使用 string quoted = RE::QuoteMeta(src_str);
而不是使用它,它将转义字符串中的所有特殊正则表达式字符,包括反斜杠。
source:引用元字符
string sContent="the path is e:\develop\East\parser(delay)";
string path="e:\develop\East\parser(delay)";
char sRegex[128]; sprintf(sRegex, "\Q%s\E", src_str);
pcrecpp::RE(sRegex).PartialMatch(sContent);
不匹配,导致"\East" will abort '\Q'
。我该如何解决这个错误?
是的,这就是 \Q
..\E
功能的问题。
您可以使用 string quoted = RE::QuoteMeta(src_str);
而不是使用它,它将转义字符串中的所有特殊正则表达式字符,包括反斜杠。
source:引用元字符