您的位置:首页 > 编程语言 > C语言/C++

Regexp使用示例(C++代码)

2012-02-21 15:18 225 查看
1 判断一个字符串是否为ip地址:

Regexp reg("^[0-9]\\{1,3\\}\\.[0-9]\\{1,3\\}\\.[0-9]\\{1,3\\}\\.[0-9]\\{1,3\\}$");
String ip="192.168.1.222";
bool match=false;
match = ip.matches(reg); // true


待续....

附录——规则表达式规则

; Minimalistic basic regular expressions information
;  ^ matches start of string
;  $ matches end of string
;  . matches any character
;  [list] matches one character in the list
;  [^list] matches one character not in list
;    Lists can be individual characters or ranges char-char. You can insert ]
;    by making it the first character in list and ^ by making it not the first
;    character
;  * matches preceeding expression any number of times (including zero)
;  \+ matches preceeding expression at least one time
;  \? matches preceeding expression zero or one time
;  \{N\} matches preceeding expression exactly N times
;  \{N,\} matches preceeding expression N or more times
;  \{N,M\} matches preceeding expression between N and M times
;  \( \) captures the contained subexpression
; Remember matches are greedy, they will match as much as possible
; You must escape ^ $ . * [ and \ with \ whenever you want them to be normal
;  characters except in lists
; Please see the manual pages for grep and sed for more information
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐