0
即时通讯在C++中使用正则表达式,并希望regex_search *和+符号,但它不会工作,因为它们是正则表达式符号。 (使用命名空间std)C + +搜索“正则表达式运算符”与正则表达式
string s = "15 * 12";
regex rx("*");
bool flag = regex_search(s, rx);
和
terminating with uncaught exception of type std::__1::regex_error: One of *?+{ was not preceded by a valid regular expression.
我该如何解决呢?
使用'\\'转义它们 –
当然,使用正则表达式执行此搜索是矫枉过正的。 –
@PeteBecker是的,在这个例子中,当然,它只是一个例子;) –