简体   繁体   English

regex_match有什么问题? 非常简单的表达

[英]what is wrong with regex_match? very simple expression

I'm using VS2010 and coding c++ console application and faced the problem 我正在使用VS2010和编码c ++控制台应用程序并遇到了问题

#include <regex>
using namespace std;

//...

if (!regex_match("abab",regex("(ab?)*")))
{
  //the problem is - why we are here? why it doesn't match?
}

checked here http://regexpal.com/ - it matches 在这里查看http://regexpal.com/ - 它匹配

Very simple: regex_match only returns true if the entire sequence gets matched. 非常简单:如果整个序列匹配,则regex_match仅返回true。 You may want to use regex_search if you want to see if a string contains your regex. 如果要查看字符串是否包含正则表达式,可能需要使用regex_search。

"ab?" “AB?” matches "aba", the repeater ("()*")make this match once. 匹配“aba”,转发器(“()*”)使此匹配一次。 The remainder is "b", so it's not a full match. 余数是“b”,所以它不是完全匹配。

I'm sorry, I misread the regex. 对不起,我误读了正则表达式。 It should be a full match. 它应该是完全匹配。 Weird enough: 很奇怪:

regex_match("aab", regex("(ab?)*")) == true

Seems to be a bug within the stl used (tested with QT Creator 2010.05, makespec = VS2010). 似乎是使用的stl中的错误(使用QT Creator 2010.05测试,makepec = VS2010)。 Replacing regex_match with regex_search in your code matches right, but the match_results are empty - indicating something still goes wrong. 在代码中用regex_search替换regex_match是正确的,但是match_results是空的 - 表示仍然出错。

With VS2012 all tests matched correctly. 使用VS2012,所有测试都匹配正确。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM