C++ Can';t在C+中找出正则表达式+;
我对正则表达式不熟悉,不能真正理解它 我只是想匹配任何字母:C++ Can';t在C+中找出正则表达式+;,c++,regex,mingw,C++,Regex,Mingw,我对正则表达式不熟悉,不能真正理解它 我只是想匹配任何字母: int main() { regex("[a-z]") return 1; } 当我运行它时,我得到一个编译时错误: terminate called after throwing an instance of 'std::regex_error' what(): regex_error This application has requested the Runtime to terminate it in
int main() {
regex("[a-z]")
return 1;
}
当我运行它时,我得到一个编译时错误:
terminate called after throwing an instance of 'std::regex_error'
what(): regex_error
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
但是,更简单的示例可以很好地工作:
int main() {
regex("a")
return 1;
}
我确信我缺少一些基本语法,我尝试添加regex::ECMAScript标志,但没有效果
请注意,我没有尝试使用regex对象,事实上我甚至没有存储它。我只是尝试使用构造函数创建它,如这里给出的示例所示:
编译器是GCC 4.8.1。通过指定标志解决了问题:
regex("pattern", std::regex_constants::basic)
没有解释的反对票是怎么回事?无论如何,匹配是后一个问题,我只想创建一个对象,它是一个什么样的模式。什么编译器?什么版本?@JamesKanze gcc 4.8.1据我所知,正则表达式在g++4.8.2(我的版本)中不起作用;我怀疑它们在早期版本中是否有效。(您的代码在VS 2013中运行良好。)