c语言中match用法,C ++中的match_results prefix()和suffix()

在本文中,我们将讨论C ++ STL中match_results::prefix()和match_results::suffix()函数的工作原理,语法和示例。

什么是C ++ STL中的match_results?

std::match_results是一个类似于容器的特殊类,用于保存匹配的字符序列的集合。在此容器类中,正则表达式匹配操作可找到目标序列的匹配项。

什么是match_results::prefix()?

match_results::prefix()函数是C ++ STL中的内置函数,在头文件中定义。prefix()用于获取与该函数关联的对象的先前match_results。此函数返回match_results对象的后续序列的引用。

语法match_results.prefix();

参数

此函数不接受任何参数。

返回值

此函数返回匹配序列之前的字符串或序列的常量引用。

示例Input: string str = "nhooo.coms";

regex R("Points");

smatch Mat;

regex_search(str, Mat, R);

Mat.prefix();

Output: Tutorials

字首()

示例#include 

using namespace std;

int main() {

string str = "nhooo.coms";

regex R("Points");

smatch Mat;

regex_search(str, Mat, R);

cout<

if (!Mat.empty()) {

cout <

}

return 0;

}

输出结果

如果我们运行上面的代码,它将生成以下输出-String prefix is : Tutorials

什么是match_results::suffix()?

match_results::suffix()函数是C ++ STL中的内置函数,在头文件中定义。suffix()用于获取与该函数关联的对象的后续match_results。此函数返回match_results对象的后续序列的引用。

语法match_results.suffix();

参数

此函数不接受任何参数。

返回值

此函数返回匹配序列之后的字符串或序列的常量引用。

示例Input: std::string str("nhooo.coms is the best");

std::smatch Mat;

std::regex re("Points");

std::regex_match ( str, Mat, re );

Mat.suffix();

Output: is the best

后缀()

示例#include 

using namespace std;

int main() {

string str = "nhooo.coms is the best";

regex R("Points");

smatch Mat;

regex_search(str, Mat, R);

cout<

if (!Mat.empty()) {

cout <

}

return 0;

}

输出结果

如果我们运行上面的代码,它将生成以下输出-String prefix is : is the best

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值