C++中Regex
来源:互联网 发布:火车头淘宝采集规则 编辑:程序博客网 时间:2024/05/16 12:05
在windows下使用C/C++中的正则表达式时,c regex.h 和boost regex不支持
For example: \ca is the same as \u0001, \cb the same as \u0002, and so on...\xhhASCII charactera character whose code unit value has an hex value equivalent to the two hex digits hh.
For example: \x4c is the same as L, or \x23 the same as #.\uhhhhunicode charactera character whose code unit value has an hex value equivalent to the four hex digitshhhh.\0nulla null character (same as \u0000).\intbackreferencethe result of the submatch whose opening parenthesis is the int-th (int shall begin by a digit other than 0). See groups below for more info.\ddigita decimal digit character \Dnot digitany character that is not a decimal digit character\swhitespacea whitespace character \Snot whitespaceany character that is not a whitespace character\wwordan alphanumeric or underscore character \Wnot wordany character that is not an alphanumeric or underscore character\charactercharacterthe character character as it is, without interpreting its special meaning within a regex expression.
Any character can be escaped except those which form any of the special character sequences above.
Needed for: ^ $ \ . * + ? ( ) [ ] { } |[class]character classthe target character is part of the class [^class]negated character classthe target character is not part of the class
这里的'\' 会被转义
而不知为何 在使用反斜杠转义其他字符的时候 要先转义反斜杠字符
如:
regex rx("^https?://[a-z]+\\.baidu\\.com/?.*");这个正则表达式与下列字符串匹配
string st("https://tieba.baidu.com/dsadw");
regex_match(st.begin(), st.end(), rx);时,如果完全匹配正则表达式则返回True否则返回False
而
regex_search(st.c_str(),res,rx);
则会将st中所有与rx匹配的片段保存到res中返回。如果片段>=1则返回true否则返回false
提供了一个cmatch类
typedef match_results<const char*> cmatch
cmatch res;这样可以定义res。
提供了一个
regex_replace(st, rx, std::string(""));用string("")(字面值)来替换上面search到的片段。
总结:使用起来有点生疏,反斜杠先转义反斜杠再转义其他字符要记住。
0 0
- C++regex
- 如何在Open C/C++应用中使用Boost.Regex
- c正则--regex
- C++:Regex正则表达式
- C++:Regex正则表达式
- c regex 用法
- C++:Regex正则表达式
- net中使用Regex
- C++中Regex
- C语言正则表达式regex
- C++Regex库安装小结
- c/c++ regex正则使用
- 在C中使用正则表达式<regex.h>--win32下载后也可用
- 在C中使用正则表达式<regex.h>--win32下载后也可用
- C++中三种正则表达式比较(C regex,C ++regex,boost regex)
- C++中三种正则表达式比较(C regex,C ++regex,boost regex)
- C++中三种正则表达式比较(C regex,C ++regex,boost regex)
- C++中三种正则表达式比较(C regex,C ++regex,boost regex)
- PAT乙级.1046. 划拳(15)
- 第二章 java基础(常量使用示例)
- FFmpeg中的滤镜(一):滤镜概念及命令规则
- Linux学习笔记--命令别名与历史命令
- c 语言中内存的动态分配(allocate)和释放(free)
- C++中Regex
- JAX-RS -- Java API for RESTful Web Services
- SSH端口转发与内网穿透
- Why was SCTP Selected for WebRTC’s Data Channel?
- UVA 10780 C - Again Prime? No Time.
- Debug Extension MEX 开放了
- SpringBoot 1.1.9.RELEASE升级1.3.6.RELEASE所遇异常
- Again Prime? No Time.(UVA 10780)
- HDU 3982 (半平面交 多边形和圆面积交)