c++正则表达式

问下大佬 c++正则表达式库咋用的 有没有啥实例
我想自己匹配个文本 文本是这样的 "@4515j" @不变去后面的字符 @(.*?) 正则表达式我也有了就不知道咋去实践

阅读 3.1k
1 个回答
...
#include <string>
#include <regex>

..... {
    std::string st(....);
    std::regex exp("@(.*?)");

    std::smatch smatch; // same as std::match_results<string::const_iterator> sm;
    
    // 遍历匹配
    while(std::regex_search(st, smatch, exp)) {
        // 遍历子分组
        for(auto x = smatch.begin(); x != m.end(); x++)
            std::cout << x->str() << std::endl;
        // 直接输出某个子分组
        std::cout << smatch.format("$1");
    }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题