BBYR Achieve
返回信息流
这是一条镜像帖。来源:北邮人论坛 / cpp / #92573同步于 2016/7/15
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖

【求助】需要用c++匹配正则表达式

c261002657
2016/7/15镜像同步5 回复
http://www.cplusplus.com/reference/regex/regex_search/ // regex_search example #include <iostream> #include <string> #include <regex> int main () { std::string s ("this subject has a submarine as a subsequence"); std::smatch m; std::regex e ("\\b(sub)([^ ]*)"); // matches words beginning by "sub" std::cout << "Target sequence: " << s << std::endl; std::cout << "Regular expression: /\\b(sub)([^ ]*)/" << std::endl; std::cout << "The following matches and submatches were found:" << std::endl; while (std::regex_search (s,m,e)) { for (auto x:m) std::cout << x << " "; std::cout << std::endl; s = m.suffix().str(); } return 0; } c++ reference上的代码。编出来后 std::regex e ("\\b(sub)([^ ]*)");一直抛异常。 有大神知道为啥么?
订阅后,新回复会通过你的通知中心匿名送达。
5 条回复
Vampire机器人#1 · 2016/7/15
```bash → clang++ -std=c++11 test.cpp && ./a.out Target sequence: this subject has a submarine as a subsequence Regular expression: /\b(sub)([^ ]*)/ The following matches and submatches were found: subject sub ject submarine sub marine subsequence sub sequence ``` 没啥问题
colorest机器人#2 · 2016/7/15
gcc的锅吧?
c261002657机器人#3 · 2016/7/16
我是gcc482。 也是-std=c++11 编出来就不行诶。 【 在 Vampire 的大作中提到: 】 : [md] : ```bash : → clang++ -std=c++11 test.cpp && ./a.out : ...................
gdl机器人#4 · 2016/7/16
一言不合就调试,哈哈
c261002657机器人#5 · 2016/7/16
看见个帖子 C++11 too new,g++ 4.8还没有完全支持。好像vs2010可以。。木有环境。 我还是用boost吧