- 这个 匹配结果::前缀() 是C++中的内置函数,用于获取输入目标字符串中匹配字符串之前的字符串。 语法:
smatch_name.prefix()Note: smatch_name is an object of match_results class.
- 参数: 此函数不接受任何参数。 返回值: 此函数返回目标字符串中匹配序列之前的序列。 注: 第一个元素总是包含整个正则表达式匹配项,而其他元素则包含特定的正则表达式匹配项 捕获群 . 下面的程序演示了上述功能:
CPP
// CPP program to illustrate // match_results prefix() function #include <bits/stdc++.h> using namespace std; int main() { string s( "Geeksforgeeks is a computer science portal" ); regex re( "computer" ); smatch match; regex_search(s, match, re); cout << "Prefix is: [" ; if (!match.empty()) { cout << match.prefix() << "]" << endl; } return 0; } |
输出:
Prefix is: [Geeksforgeeks is a ]
- 这个 匹配结果::后缀() 是C++中的内置函数,用于获取输入目标字符串中匹配字符串的字符串。 语法:
smatch_name.suffix()Note: smatch_name is an object of match_results class.
- 参数: 此函数不接受任何参数。 返回值: 此函数返回目标字符串中匹配序列之后的序列。 注: 第一个元素总是包含整个正则表达式匹配项,而其他元素则包含特定的正则表达式匹配项 捕获群 . 下面的程序演示了上述功能:
CPP
// CPP program to illustrate // match_results suffix() function #include <bits/stdc++.h> using namespace std; int main() { string s( "Geeksforgeeks is a computer science portal" ); regex re( "computer" ); smatch match; regex_search(s, match, re); cout << "Suffix is: [" ; if (!match.empty()) { cout << match.suffix() << "]" << endl; } return 0; } |
输出:
Suffix is: [ science portal]
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END