Boost regex not matching “\\s” to spaces
我只是从boost和c开始,我正在努力了解boost的正则表达式引擎在匹配空白时的行为。如果我使用代码:
1 2 | boost::regex rx(""); cout << regex_search("", rx); |
匹配空格,然后一切都会按预期工作,并且regex_search返回true。但是,如果我尝试将正则表达式替换为" \\\\ s"以匹配所有空格字符,那么我将永远不会获得匹配,并且以下代码始终输出false:
1 2 | boost::regex rx("\\\\s"); cout << regex_search("", rx); |
我在这里想念什么?
根据要求,这是我完整的测试用例:
1 2 3 4 5 6 7 8 9 10 | #include <boost/regex.hpp> #include <iostream> using namespace std; int main() { boost::regex rx("\\\\s", boost::regex::icase); cout << regex_search("", rx); } |
知道了-我最初使用的是来自ascend4.org/Binary_installer_for_Boost_on_MinGW的预构建库。构建Boost 1.52之后,代码将按预期工作。试图简化加速构建过程最终使我付出了数小时的挫败……现在我已经学到了教训!