如何匹配多行文字?

tra*_*er2 3 regex boost boost-xpressive

string str = "hello world!\r\naa=`xxx_1`\r\nhello world!";
sregex rx = sregex::compile(".+=`(.+)_1`");
smatch what;
if( regex_match( str, what, rx ) )
{
    std::cout << what[1] << '\n';
}
Run Code Online (Sandbox Code Playgroud)

这行不通,我使用boost.xpressive而不是boost.regex,如何匹配多行文本?

tra*_*er2 5

我已经解决了这个问题。

http://boost-sandbox.sourceforge.net/libs/xpressive/doc/html/boost_xpressive/user_s_guide/matching_and_searching.html

仅当regex从头到尾匹配整个输入时,regex_match()算法才会报告成功。如果正则表达式仅匹配输入的一部分,则regex_match()将返回false。如果要搜索字符串以查找正则表达式匹配的子字符串,请使用regex_search()算法。