欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

c++使用正則表達(dá)式提取關(guān)鍵字的方法

 更新時(shí)間:2018年08月21日 15:10:33   作者:cplus2009  
這篇文章給大家介紹了c++使用正則表達(dá)式提取關(guān)鍵字的方法,相對(duì)來(lái)說(shuō)比較簡(jiǎn)單,同時(shí)給大家提到了c++通過(guò)正則表達(dá)式提取匹配到的字符串的方法,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友參考下吧

下面看下c++通過(guò)正則表達(dá)式提取關(guān)鍵字,代碼如下所示:

string text = "岳云鵬的對(duì)象叫鐵錘";
  regex pattern("(.*)的對(duì)象叫(.*)");
 smatch results;
  if (regex_match(text, results, pattern)) {
   for (auto it = results.begin(); it != results.end(); ++it)
    cout << *it << endl;
  }
  else {
   cout << "match failed: " << text << endl;
  }
  // 岳云鵬的對(duì)象叫鐵錘
 // 岳云鵬
 // 鐵錘

下面看下C++正則表達(dá)式提取匹配到的字符串

/*
 * 輸入是789.123.456, 輸出的是789
 */
void get()
{
 std::regex ip_reg("(.*)\.123\.456");
 std::smatch matchResult;
  string inputStr;
  std::getline(std::cin,inputStr);
  //正則匹配
  if (std::regex_match(inputStr,matchResult,ip_reg))
  {
   cout << "Match: ";
   //打印子表達(dá)式結(jié)果
   for (size_t i = 1; i < matchResult.size(); ++i)
   {
    cout << matchResult[i] << " ";
   }
  }
  else
  {
   cout << "Not Match!";
  }
 }

總結(jié)

以上所述是小編給大家介紹的c++使用正則表達(dá)式提取關(guān)鍵字的方法,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論