Boost Regex regex_match(grep选项) [英] Boost Regex regex_match (grep option)

查看:107
本文介绍了Boost Regex regex_match(grep选项)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





环境:Windows 7(32位),Visual Studio 2010(Visual C ++)



我正在尝试使用Boost REGEX regex_match算法。

我正在使用它的grep标志。

我的代码如下所示(a)*匹配字符串aaa,但b仍然是假的。









Hi,

Environment: Windows 7 (32 bit), Visual Studio 2010 (Visual C++)

I am trying to use Boost REGEX regex_match algorithm.
I am using its grep flag.
My code is as follows and here (a)* matches string "aaa", but still b comes out to be false.




bool MatchWithGrep(string& pattern, string& data)
{

	const boost::regex e(pattern.c_str(), boost::regex::grep);
	return regex_match(data.c_str(), e);

}



我传递以下参数


I am passing following parameters

bool b = MatchWithGrep("(a)*\\n123", "aaa");









任何人都可以帮我找到我的代码有什么问题吗?

提前谢谢。





Can any one help me to find whats wrong with my code?
Thanks in advance.

推荐答案

不 - 但是你的数据和模式不匹配。

您正在搜索零或更多'a'后跟换行符和字符串'123',这在aaa的示例数据中不存在

尝试这样称呼:

No - but your data and the pattern do not match.
You are searching for "zero or more 'a' followed by a newline character and the string '123'" which is not present in your sample data of "aaa"
Try calling it this way:
bool b = MatchWithGrep("(a)*", "aaa\\n123");

它可能会更好......

And it might work better...


这篇关于Boost Regex regex_match(grep选项)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆