如何使用正则表达式,获得多个匹配结果
match_results results;
string str( "The book cost $12.34" );
rpattern pat( "cost \\$(\\d+)(\\.(\\d\\d))?" );
// Match a dollar sign followed by one or more digits,
// optionally followed by a period and two more digits.
// The double-escapes are necessary to satisfy the compiler.
match_results::backref_type br = pat.match( str, results );
if( br.matched ) {
cout << "match success!" << endl;
cout << "price: " << br << endl;
} else {
cout << "match failed!" << endl;
}
这是标准例子,如果str包含多个匹配结果,如何得到,显示出来
string str( "The book cost $12.34" );
rpattern pat( "cost \\$(\\d+)(\\.(\\d\\d))?" );
// Match a dollar sign followed by one or more digits,
// optionally followed by a period and two more digits.
// The double-escapes are necessary to satisfy the compiler.
match_results::backref_type br = pat.match( str, results );
if( br.matched ) {
cout << "match success!" << endl;
cout << "price: " << br << endl;
} else {
cout << "match failed!" << endl;
}
这是标准例子,如果str包含多个匹配结果,如何得到,显示出来
...全文
相关推荐
Node.js-execall-发现多个正则表达式匹配的字符串
execall - 发现多个正则表达式匹配的字符串
C#正则表达式匹配与替换字符串功能示例
主要介绍了C#正则表达式匹配与替换字符串功能,结合具体实例形式分析了C#字符串正则替换相关类、方法的使用技巧与相关注意事项,需要的朋友可以参考下
js正则表达式最长匹配(贪婪匹配)和最短匹配(懒惰匹配)用法分析
主要介绍了js正则表达式最长匹配(贪婪匹配)和最短匹配(懒惰匹配)用法,结合实例形式分析了贪婪匹配与懒惰匹配的具体用法与相关注意事项,需要的朋友可以参考下
Python利用正则表达式匹配并截取指定子串及去重的方法
主要介绍了Python利用正则表达式匹配并截取指定子串及去重的方法,涉及Python正则表达式匹配及字符串截取操作的相关技巧,具有一定参考借鉴价值,需要的朋友可以参考下
python使用正则表达式匹配字符串开头并打印示例
主要介绍了python使用正则表达式匹配字符串开头并打印的方法,结合实例形式分析了Python基于正则表达式操作字符串的相关技巧,需要的朋友可以参考下


工具平台和程序库
