regex_search C ++不匹配子串

时间:2016-04-25 05:57:43

标签: c++ regex c++11

regex_search不匹配" ter"在"计算机计算机"当我使用以下代码时 -

#include <iostream>
#include <regex>

using namespace std;

int main() {
    string str("Computer Computer");
    cout << regex_search(str, regex("ter"));
    return 0;
}

上面的代码给了我0,而显然有&#34; ter&#34;在这个主题。那么这里发生了什么。我知道PHP的正则表达式匹配子串很好,但这里有什么不对吗?

我使用的是C ++ 11 GCC,这是一个问题,因为我在某处读到它对正则表达式支持不足。

1 个答案:

答案 0 :(得分:1)

它重新运行1类型bool,这意味着在单词中找到模式匹配。运行此程序。

#include <stdio.h>
#include<iostream>
#include <regex>
using namespace std;
int main(void) {
    cout << regex_search(string("Computer Computer"), regex("ter"));//1
    cout << regex_search(string("Computer Computer"), regex("tesdsr"));//0
    return 0;
}
相关问题