C+中的简单正则表达式用法+; 我尝试用默认的LIB在C++中做最基本的正则表达式例子,并且总是崩溃或者不连贯的行为。 // with -std=c++11 #include <regex> using namespace std; int main() { // Copied from the documentation, this one works if (std::regex_match ("subject", std::regex("(sub)(.*)") )) std::cout << "string matched\n"; // The most simple example I could try, crash with "regex_error" if (std::regex_match ("99", std::regex("[0-9]*") )) std::cout << "integer matched\n"; } //带-std=c++11 #包括 使用名称空间std; int main() { //从文档中复制,这一个有效 如果(std::regex_匹配(“主题”,std::regex((*))) std::cout

C+中的简单正则表达式用法+; 我尝试用默认的LIB在C++中做最基本的正则表达式例子,并且总是崩溃或者不连贯的行为。 // with -std=c++11 #include <regex> using namespace std; int main() { // Copied from the documentation, this one works if (std::regex_match ("subject", std::regex("(sub)(.*)") )) std::cout << "string matched\n"; // The most simple example I could try, crash with "regex_error" if (std::regex_match ("99", std::regex("[0-9]*") )) std::cout << "integer matched\n"; } //带-std=c++11 #包括 使用名称空间std; int main() { //从文档中复制,这一个有效 如果(std::regex_匹配(“主题”,std::regex((*))) std::cout,c++,regex,std,C++,Regex,Std,正如@Wiktor Stribiżew所说,只是我的编译器太旧了。正在更新编译器(从gcc 4.1到gcc 4.9)解决了这个问题!参见.HUM,那么我应该如何实际使用C++中的正则表达式?@ DILINURR GCC现在是6.1。你可以尝试升级你的编译器。@ Dillinur:至少不要使用匹配空字符串的正则表达式。为什么你需要一个空的(空)字符串?只需使用 [09]+。我正在尝试所有可能的正则表达式,任何“*”+”字符都会使正则表达式构造函数崩溃。。

正如@Wiktor Stribiżew所说,只是我的编译器太旧了。正在更新编译器(从gcc 4.1到gcc 4.9)解决了这个问题!

参见.HUM,那么我应该如何实际使用C++中的正则表达式?@ DILINURR GCC现在是6.1。你可以尝试升级你的编译器。@ Dillinur:至少不要使用匹配空字符串的正则表达式。为什么你需要一个空的(空)字符串?只需使用<代码> [09]+。我正在尝试所有可能的正则表达式,任何“*”+”字符都会使正则表达式构造函数崩溃。。