提升正则表达式子串匹配

bob*_*bob 4 c++ regex boost

如果模式"regular"是变量st的子字符串,我想返回输出"匹配".这可能吗?

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;
  }
}
Run Code Online (Sandbox Code Playgroud)

Mic*_*son 15

boost :: regex_match只匹配整个字符串,你可能需要boost :: regex_search.


Ale*_*lli 7

regex_search做你想要的; regex_match记录为

确定给定的正则表达式是否匹配给定字符序列的所有内容

(重点在于我引用的原始URL).