c++ - boost 正则表达式子字符串匹配

标签 c++ regex boost

如果模式“regular”是变量 st 的子字符串,我想返回输出“match”。这可能吗?

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;
  }
}

最佳答案

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

关于c++ - boost 正则表达式子字符串匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2061885/

相关文章:

c++ - 当类型是未知模板参数时使用原始指针

javascript - 确定字符串中的组

c++ - Boost beast 在接受期间操纵 http 响应 header

c++ - boost::spirit ,如何获取占位符的 "value"

c++ - QMainWindow::splitDockWidget 的 QDockWidget 拉伸(stretch)因子?

c++ - 为什么我的 Win32(c++, visual studio 2013) 窗口没有出现?

正则表达式匹配字符与两个字符的负后视

regex - 这些模式可以通过正则表达式或上下文无关的语法进行匹配吗?

c++ - boost Date_Time 日期解析不起作用

C++ 错误 C4430 int 假定