Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ boostregexp匹配_C++_Regex_Boost - Fatal编程技术网

C++ boostregexp匹配

C++ boostregexp匹配,c++,regex,boost,C++,Regex,Boost,我有这样一个正则表达式 boost::regex isAgent ("Mozilla/\d[.]\d \(Windows NT \d[.]\d; (Win64; x64;|WOW64;)?(.*?)\) Gecko/\d{8} Firefox/\d\d[.]\d", boost::regex::perl); if (boost::regex_search(auxAgent.c_str(), match, reg)){...}... 我知道在auxAgent中,我有一个示例Moz

我有这样一个正则表达式

boost::regex isAgent
    ("Mozilla/\d[.]\d \(Windows NT \d[.]\d; (Win64; x64;|WOW64;)?(.*?)\) Gecko/\d{8} Firefox/\d\d[.]\d",
    boost::regex::perl);
if (boost::regex_search(auxAgent.c_str(), match, reg)){...}...
我知道在
auxAgent
中,我有一个示例
Mozilla/5.0(windowsnt 6.1;Win64;x64;rv:25.0)Gecko/20100101 Firefox/25.0

在这一页上
所有的东西都匹配,但不是在Boost中,我做了什么?C++中的< /P> < P>,字符“代码> \/CODE”需要被转义。所以,如果你想逃避任何事情,你需要做
\\
。这应该可以解决问题。无论何时在字符串中使用反斜杠,都需要像这样对其进行转义。如果你需要用正则表达式在字符串中找到它,你需要用
\\\\\

搜索它。我认为Pawel Stawarz是正确的。你应该避开反斜杠。但以下是您需要转义的所有字符:

^.$|( ) [ ] * + ? \ /

替换\为\\

替换?用\

等等

资料来源:

棘爪是正确的。为了澄清,这意味着您的
isAgent
变量应该这样定义:
boost::regex-isAgent(“Mozilla/\\d\\\.\\d\\(Windows NT\\d\\.\\d;;(Win64;x64;| WOW64;)?(.*)Gecko/\\d{8}Firefox/\\d\\d\\\.\\d”,boost::regex::perl)