boost regex子字符串匹配 [英] boost regex sub-string match
本文介绍了boost regex子字符串匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果模式regular是变量st的子字符串,我想返回输出match。这是可能吗?
int main()
{
string st =一些正则表达式是Regxyzr ;
boost :: regex ex([Rr] egular);
if(boost :: regex_match(st,ex))
{
cout< match<< endl
}
else
{
cout<< 不匹配< endl
}
}
解决方案boost :: regex_match只匹配整个字符串,你可能想要boost :: regex_search。
I want to return output "match" if the pattern "regular" is a sub-string of variable st. Is this possible?
int main()
{
string st = "some regular expressions are Regxyzr";
boost::regex ex("[Rr]egular");
if (boost::regex_match(st, ex))
{
cout << "match" << endl;
}
else
{
cout << "not match" << endl;
}
}
解决方案
The boost::regex_match only matches the whole string, you probably want boost::regex_search instead.
这篇关于boost regex子字符串匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文