草庐IT

regex_extract

全部标签

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库的编译选项与我在项目中使用的选项不同,但我

c++ - 您可以使用 Boost.Regex 来解析流吗?

我正在尝试使用Boost.Regex来解析字符串中的单词和数字。这是我目前所拥有的:#include#include#include#include#includeusingnamespacestd;usingnamespaceboost;intmain(){regexre("(""([a-z]+)|""(-?[0-9]+(\\.[0-9]+)?)"")");strings="hereisa\tlistofWords.andsome1239.32numbersto3323parse.";sregex_iteratorm1(s.begin(),s.end(),re),m2;BOOST_F

c++ - 如何循环 std::regex_search 的结果?

调用std::regex_search后,出于某种原因,我只能从std::smatch获取第一个字符串结果:Expression.assign("rel=\"nofollow\">(.*?)");if(std::regex_search(Tables,Match,Expression)){for(std::size_ti=1;i所以我尝试用另一种方式-使用迭代器:conststd::sregex_token_iteratorEnd;Expression.assign("rel=\"nofollow\">(.*?)");for(std::sregex_token_iteratori(Ta

c++ - std::regex 是否支持 "(?i)"不区分大小写?

我正在使用VisualStudio2010。这...std::regexpattern("(?i).*a.*");...抛出这个...std::tr1::regex_error-正则表达式错误...而且我找不到任何说明std::regex是否支持(?i)不区分大小写的语法。谁能确认/否认std::regex不支持将(?i)作为不区分大小写的前缀? 最佳答案 该标准仅要求符合POSIX正则表达式语法(不包括像这样的Perl扩展)和符合ECMAScript正则表达式规范(除了少数异常(exception),根据ISO14882-2011

c++ - 如何使用新的 c++0x regex 对象在字符串中重复匹配?

我有一个字符串:"hello1,hello2,hello17,anddone!"我想对它重复应用这个正则表达式:hello([0-9]+)并且能够以某种方式遍历匹配项及其捕获组。我已经在c++0x中成功地使用了“正则表达式”来找到字符串中某物的第一个匹配项并检查捕获组的内容;但是,在找到所有匹配项之前,我不确定如何在字符串上多次执行此操作。帮助!(平台是visualstudio2010,以防万一。) 最佳答案 不要使用regex_match,使用regex_search。您可以在此处找到示例:http://www.codeguru.