为什么正则表达式阻塞在replace上? 为什么这段C++代码块永远存在?< /P> string word = " a\n"; regex indent("^( |\t)*"); word = regex_replace(word, indent, ""); 为什么这段C++代码会很快终止?< /P> string word = " a\n"; regex indent("^( |\t)+"); word = regex_replace(word, indent, ""); string word = " a\n"; regex indent("^( |\t)+?"); word = regex_replace(word, indent, "");
再加上一个转折点,为什么这会很快终止为什么正则表达式阻塞在replace上? 为什么这段C++代码块永远存在?< /P> string word = " a\n"; regex indent("^( |\t)*"); word = regex_replace(word, indent, ""); 为什么这段C++代码会很快终止?< /P> string word = " a\n"; regex indent("^( |\t)+"); word = regex_replace(word, indent, ""); string word = " a\n"; regex indent("^( |\t)+?"); word = regex_replace(word, indent, "");,c++,regex,C++,Regex,再加上一个转折点,为什么这会很快终止 string word = " a\n"; regex indent("^( |\t)+"); word = regex_replace(word, indent, ""); string word = " a\n"; regex indent("^( |\t)+?"); word = regex_replace(word, indent, ""); 我希望“^(|\t)+?”与“^(|\t)*” 我使用LBC+++和LLVM和标准C++正则表达式库。
string word = " a\n";
regex indent("^( |\t)+");
word = regex_replace(word, indent, "");
string word = " a\n";
regex indent("^( |\t)+?");
word = regex_replace(word, indent, "");
我希望“^(|\t)+?”
与“^(|\t)*”
我使用LBC+++和LLVM和标准C++正则表达式库。
< P>代码是好的。正则表达式库在您的libc++版本中大多没有实现。您最好使用另一个库,如boost或更新版本的libc++。我的猜测是,^(|\t)*
不匹配任何内容(即*表示0或更多,因此它匹配一个空格、一个选项卡或空字符串),而现有的(错误的)算法在输入字符串中找不到任何内容。。。永远。换句话说,您在regex实现中遇到了一个bug。我下载并编译了libc++的最新版本,并且“^(|\t)*”
版本不再阻塞。所以我要把它记在一个旧库中。上次我听说libstdc++的
不完整。