正则表达式和增强

Regular expression and Boost

本文关键字:增强 正则表达式      更新时间:2023-10-16

我对提升中的以下正则表达式有问题:

const boost::regex eComment("^/*[sS]*?*/|^//");

当我使用此正则表达式运行程序时,它中止并显示消息:

terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::regex_error> >'
what():  Invalid preceding regular expression prior to repetition operator.  
The error occured while parsing the regular expression: '^/*[sS]*?*>>>HERE>>>/|^//'.

此正则表达式应该*.cpp文件中找到带有注释的行,但如果行中有代码,则应跳过。

我认为

问题是你忘记转义反斜杠字符。每个反斜杠应加倍,如 \\s\\S 而不是 \s\S

希望对你有帮助