阅读背景:

正则表达式程序没有捕获异常,其他问题

来源:互联网 

When I run this code:

当我运行此代码时:

#include <iostream>
#include <regex>

using namespace std;

main () {
    const string source = "hello(abc_def)";
    const regex regexp("he(l)lo.*");
    smatch m;
    if (regex_match(source, m, regexp)) {
        cout << "Found, group 1 = " << m[1].str() << endl;
    } else {
        cout << "Not found" << endl;
    }
    const regex regexp2("hello\((\w+)\)");
    try {
        if (regex_match(source, m, regexp2)) {
            cout << "Found, group 1 = " << m[1].str() << endl;
        } else {
            cout << "Not found" << endl;
        }
    } catch(const exception& exc) {
        cout << "Got exception: " << exc.what() << endl;
    }
}
#include <i



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: