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'如何修复此错误?
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);It doesn't match, cause "\\East" will abort '\Q'。How can I fix this error?
最满意答案
是的,这是\Q .. \E功能的问题。
您可以使用string quoted = RE::QuoteMeta(src_str);而不是使用它string quoted = RE::QuoteMeta(src_str); 这将转义包含反斜杠的字符串中的所有特殊正则表达式字符。
来源 :引用METACHARACTERS
Yes, that's the problem with the \Q..\E feature.
Instead of using it, you can use string quoted = RE::QuoteMeta(src_str); that will escape all special regex characters in a string including backslashes.
source: QUOTING METACHARACTERS
更多推荐
发布评论