我只是想匹配“{”。但不知道为什么会出现这个错误:
Run Code Online (Sandbox Code Playgroud)terminate called after throwing an instance of 'std::regex_error' what(): regex_error Aborted (core dumped)
在 Ubuntu 上使用 g++ 版本 4.6.3 进行编译
g++ -std=c++0x a.c
Run Code Online (Sandbox Code Playgroud)
#include<iostream>
#include<regex>
using namespace std;
main(int argc,char**argv){
if (regex_match("{1}" , std::regex ("[{]"))) {
cout<<"Hello World"<<endl;
}
}
Run Code Online (Sandbox Code Playgroud)
我还检查了ECMAScript详细信息,这个正则表达式应该匹配。当我使用 like 时它也不匹配:std::regex ("\\{"))
我怎么了?
您至少需要gcc 4.9才能使正则表达式与 gcc 一起使用,一旦您将添加 4.9 版本.*以使其与字符串的其余部分匹配:
if (regex_match("{1}" , std::regex ("[{].*"))) {
^^
Run Code Online (Sandbox Code Playgroud)
http://coliru.stacked-crooked.com/a/99e405e66906804d
| 归档时间: |
|
| 查看次数: |
9493 次 |
| 最近记录: |