草庐IT

menta-regex

全部标签

c++ - 在 libc++ 上,为什么 regex_match ("tournament", regex ("tour|to|tournament")) 失败?

在http://llvm.org/svn/llvm-project/libcxx/trunk/test/re/re.alg/re.alg.match/ecma.pass.cpp,存在以下测试:std::cmatchm;constchars[]="tournament";assert(!std::regex_match(s,m,std::regex("tour|to|tournament")));assert(m.size()==0);为什么这个匹配会失败?在VC++2012和boost上,匹配成功。在Chrome和Firefox的Javascript上,"tournament".mat

c++ - clang 中 regex_constants 的错误实现?

如standard中所述:match_prev_avail:--first是一个有效的迭代器位置。设置后,会导致match_not_bol和match_not_bow被忽略但我运行以下代码并得到:#include#includeusingnamespacestd;intmain(){regexre0("^bcd");stringstr="abcd";std::string::iteratorstart=str.begin()+1;cout输出:010match_prev_avail似乎被match_not_bol覆盖了。 最佳答案

c++ - 为什么 Regex (c++) 需要指数时间?

我正在做一些教科书中的正则表达式问题,其中内容如下:[匹配]在行首以整数开始并在行尾以单词结束的所有字符串。”我为此编写了以下正则表达式:^[0-9]+\s.*+\b[a-zA-Z]+$然而,当我使用以下代码在C++中实现它时:#include#include#include#includeintmain(){clock_tt;boolmatch;std::stringexp="^[0-9]+\\s.*+\b[a-zA-Z]+$";std::stringstr="1afewwords1";std::strings(str);std::smatchm;std::regexe(exp);w

使用 Boost Regex 的 C++ 正则表达式

我试图在C++中获取一个字符串并找到其中包含的所有IP地址,并将它们放入一个新的vector字符串中。我已经阅读了很多关于正则表达式的文档,但我似乎无法理解如何执行这个简单的功能。我相信我可以使用这个Perl表达式来查找任何IP地址:re("\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b");但我仍然对如何

c++ - Visual Studio regex_iterator 错误?

我在使用VisualStudio2013,我看到了一个我认为是错误的东西,我希望有人可以确认吗?stringfoo{"A\nB\rC\n\r"};vectorbar;for(sregex_iteratori(foo.cbegin(),foo.cend(),regex("(.*)[\n\r]{1,2}"));i!=sregex_iterator();++i){bar.push_back(i->operator[](1).str());}此代码在VisualStudio正则表达式库中命中调试断言:regex_iteratororphaned如果我在for循环之外定义regex没问题:str

c++ - 用 gcc 编译 std::regex_iterator

我可以使用g++-ctest.cpp-std=c++0x创建.o文件,但无法链接它,出现下一个错误:test.cpp:(.text+0xe5):undefinedreferenceto`std::regex_iterator>::regex_iterator(charconst*,charconst*,std::basic_regex>const&,std::bitset)'test.cpp:(.text+0xf1):undefinedreferenceto`std::regex_iterator>::regex_iterator()'代码:#include#include#inclu

C++ 11 正则表达式 : checking if string starts with regex

我正在使用C++11的支持,并想检查字符串的开头是否与正则表达式匹配。[如果有帮助,我可以切换到Boost,但我的印象是它们基本相同。]显然,如果我可以控制表达式的实际文本表示,我可以只粘贴^在它的开头作为anchor。但是,如果我只有一个regex怎么办?(或basic_regex)对象?我可以修改它代表的正则表达式来添加anchor吗?或者我必须使用regex_search,得到结果,检查是否从位置0开始? 最佳答案 您可以在使用regex_search时添加std::regex_constants::match_continu

c++ - 使用 boost::regex_search 忽略大小写

如何在C++中使用boost::regex_search忽略大小写标志或常量?请发布一个简单的示例。谢谢! 最佳答案 你需要这样的东西boost::regexregex("yourexpressionhere",boost::regex::icase);boost::smatchwhat;stringmystring;boolsearch_result=boost::regex_search(mystring.begin(),mystring.end(),what,regex); 关于c

c++ - std::regex 线程安全吗?

与Isastaticboost::wregexinstancethread-safe?相关但对于标准化版本。我可以从具有相同regex对象的多个线程调用regex_search吗? 最佳答案 声称std::regex在各个方面都是线程安全的是一个非常大胆的声明。C++11标准不对正则表达式库做出这样的保证。但是,查看std::regex_search的原型(prototype)显示它将basic_regex对象作为const参数。这意味着它受到标准库的保护,保证const修饰符impliesthread-safety关于该参数的函数

c++ - 使用 mingw-w64 工具链时,以 Release模式链接的 Regex Boost 库会发出 "duplicate section has different size"警告

在Release模式下链接我的项目时,我收到以下警告:myProject-libs/release/libboost_regex-mt-s-1.50.0.a(cpp_regex_traits.o):duplicatesection`.data$_ZZN5boost16cpp_regex_traitsIcE21get_catalog_name_instEvE6s_name[boost::cpp_regex_traits::get_catalog_name_inst()::s_name]'hasdifferentsize我怀疑原因可能是boost库的编译选项与我在项目中使用的选项不同,但我