STL和正则表达式

时间:2013-04-29 16:54:36

标签: c++ regex c++11 stl

我正在尝试编写一个在C ++中使用标准库方法的字符串解析器。我想解析一个以换行符或';'结尾的传入字符串子串。我不断从我创建的正则表达式对象中获取异常。我的模式是:

string pattern = "(.+[\\n\\r;])";
regex cmd_sep(pattern);

我在使用和不使用regex_constants :: extended或basic标志的情况下尝试过它。

1 个答案:

答案 0 :(得分:0)

如果您使用的是boost库,最好发布错误消息。您可能错过了boost::regex代码。

试试这个

#include <boost/regex.hpp>
#include <string>
using namespace std;

int main ()
{
    string pattern = "(.+[\\n\\r;])";
    static const boost::regex cmd_sep(pattern);
    return 0;
}