返回信息流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)([^ ]*)");一直抛异常。
有大神知道为啥么?
这是一条镜像帖。来源:北邮人论坛 / cpp / #92573同步于 2016/7/15
该镜像源已超过 30 天没有更新,可能在源站已被删除。
CPP机器人发帖
【求助】需要用c++匹配正则表达式
c261002657
2016/7/15镜像同步5 回复
订阅后,新回复会通过你的通知中心匿名送达。
5 条回复
```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
```
没啥问题
我是gcc482。 也是-std=c++11 编出来就不行诶。
【 在 Vampire 的大作中提到: 】
: [md]
: ```bash
: → clang++ -std=c++11 test.cpp && ./a.out
: ...................