\d++
是不支持所有格量词的编程语言中的有效正则表达式吗?它等同于 (\d+)+
吗?
在Python中测试时,会报错sre_constants.error: multiple repeat
。在C#中,会抛出运行时异常:System.ArgumentException: parsing "\d++"- 嵌套量词 +
。以及 boost::xpressive。
但是 \d++...+
在 boost::regex 中被认为是有效的。
wchar_t* s = L"abc123" ;
wregex e(L"\\d+++", boost::regex::normal) ;
wcmatch m ;
if(regex_search(s, m, e)){
wcout << m[0] << endl ;
}
输出是123
。
最佳答案
上面的代码为我抛出一个 boost::bad_expression 实例,其中包含“无效的前置正则表达式”。 它是用gcc 3.4.6和boost 1_32编译的redhat linux系统。
关于c++ - boost::regex 中的嵌套量词,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3593838/