C++11,正则表达式应用
来源:互联网 发布:淘宝金牌店铺 编辑:程序博客网 时间:2024/06/11 22:12
一、basic_regex类
1、typedef basic_regex<char> regex;
2、typedef basic_regex<wchar_t> wregex;
实例化正则对象:regex reg("[\\d]{3}");
二、match_results类
1、typedef match_results<const char*> cmatch;
2、typedef match_results<const wchar_t*> wcmatch;
3、typedef match_results<string::const_iterator> smatch;
4、typedef match_results<wstring::const_iterator> wsmatch;
实例化匹配结果对象:smatch;
三、sub_match类
1、typedef sub_match<const char*> csub_match;
2、typedef sub_match<const wchar_t*> wcsub_match;
3、typedef sub_match<string::const_iterator> ssub_match;
4、typedef sub_match<wstring::const_iterator> wssub_match;
获取一个sub_match:ssub_match = smatch[0];
四、regex_iterator类
typedef regex_iterator<const char*> cregex_iterator;
typedef regex_iterator<const wchar_t*> wcregex_iterator;
typedef regex_iterator<string::const_iterator> sregex_iterator;
typedef regex_iterator<wstring::const_iterator> wsregex_iterator;
五、regex_token_iterator类:
typedef regex_token_iterator<const char*> cregex_token_iterator;
typedef regex_token_iterator<const wchar_t*> wcregex_token_iterator;
typedef regex_token_iterator<string::const_iterator> sregex_token_iterator;
typedef regex_token_iterator<wstring::const_iterator> wsregex_token_iterator;
用法:
1、regex_match,需要完全匹配str,才返回true
regex reg("[\\d]{3}");smatch result; BOOL bRet = regex_match(str, result,reg);2、regex_search,局部匹配str,即可返回true
regex reg("[\\d]{3}");smatch result; BOOL bRet = regex_search(str, result,reg);3、regex_iterator
// instr中,从开头到结尾,跟reg匹配的string,存入迭代器中string str = "123,456,asdfsdf";regex reg("[\\d]{3}");sregex_iterator iter(str.begin(), str.end(), reg),end;while (iter != end) {cout << iter->str() << endl;++iter;}
4、regex_replace
string str = "123,456,asdfsdf";regex reg("[\\d]{3}");string strRes = regex_replace(str,reg,"asdas");
- C/C++正则表达式应用
- c语言正则表达式应用
- C#—异常应用(正则表达式)
- C++11,正则表达式应用
- URLRewrite结合正则表达式(C#)的应用(接上篇)
- 正则表达式在objectiv-c中的简单应用
- 正则表达式的应用
- 正则表达式的应用
- 正则表达式的应用
- 正则表达式及应用
- 正则表达式应用知识
- 正则表达式应用
- 正则表达式简单应用
- 正则表达式的应用
- 正则表达式应用
- C#正则表达式应用
- 正则表达式应用
- 正则表达式的应用
- Android Studio导入项目方法
- 从Uri获得图片真实路径
- Iframe 高度自适应解决方案
- ViewPager 无线轮播
- Gulp系列教程:使用BrowserSync浏览及相关配置
- C++11,正则表达式应用
- jQuery的选择器—层次选择器
- js获取节点
- MySQL的账号密码管理
- 编写C程序容易犯错的地方
- My first java class!
- Linux中的popen函数
- dotNET_Reactor 命令行 参数大全
- TextField PasswordField