c++ - 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 中我有 exacly Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0

在此页面上 http://gskinner.com/RegExr/?37em3一切都匹配但不是在 boost ,我做错了什么?

最佳答案

在C++中,字符\需要转义。所以如果你想转义任何东西,你需要做\\。那应该可以解决问题。每当你在字符串中使用反斜杠时,你都需要像那样转义它。如果您需要使用正则表达式在字符串中找到它,则需要使用 \\\\ 进行搜索。

关于c++ - boost 正则表达式匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20307826/

相关文章:

c++ - 在 Windows 中无法从 cmake 中找到 MySQL 和 Boost includes/libs

c++ - Windows:获取 .text 部分的开始和结束

c++ - 将 cout 重定向到使用 winapi 创建的新缓冲区

c++ - 通过指针访问时的字节大小

mysql - 如何在mysql中提取数据的第一个数字?

boost - 在 make 文件中包含 boost 库

android - 具有 native 代码支持的跨平台移动框架

c# - 正则表达式匹配太多

javascript - 如何在javascript中的两个分隔符之间拆分字符串?

c++ - boost::gregorian::date 如何在内部存储日期?