C++ 在字符串中查找重复模式
我试图在字符串中找到模式,但在得到最终结果时遇到了一些困难。我有一个迭代字符串的方法,如果在输入字符串中找到子字符串,我将其添加到数组中:C++ 在字符串中查找重复模式,c++,C++,我试图在字符串中找到模式,但在得到最终结果时遇到了一些困难。我有一个迭代字符串的方法,如果在输入字符串中找到子字符串,我将其添加到数组中: string * maxRepeat(string input) { string * matches = new string[22]; for(int i = 0; i < 22; i++) matches[i] = '@'; string s = input; smatch m; for(int i = 0; i < i
string * maxRepeat(string input) {
string * matches = new string[22];
for(int i = 0; i < 22; i++) matches[i] = '@';
string s = input;
smatch m;
for(int i = 0; i < input.length()-1; i++){
for(int j = 0; j < input.length(); j++){
string foo = input.substr(j, j);
regex e("\\b(" + foo + ")([^ ]*)");
if (regex_search (input,m,e)) {
int index = 0;
for (auto x:m){
matches[index] = x;
index++;
}
}
i+=1;
}
}
return matches;
}
string*maxRepeat(字符串输入){
字符串*匹配项=新字符串[22];
对于(inti=0;i<22;i++)匹配[i]='@';
字符串s=输入;
smatch m;
对于(int i=0;i
输入字符串可能是
249249249249
,我得到的最小字符串是249249
。我将如何执行此操作直到它刚好是249
?您真的必须为此使用正则表达式吗?不,但我无法找到另一种方法来搜索模式,因为模式事先未知。只需检查子字符串是否相等,这就足够了。