Network and URL
Description | Regex |
---|---|
HTTP | \bhttps?://[a-zA-Z0-9\-.]+(?:(?:/[a-zA-Z0-9\-._?,'+\&%$=~*!():@\\]*)+)? |
HTTP | \b(https?)://([a-zA-Z0-9\-.]+)((?:/[a-zA-Z0-9\-._?,'+\&%$=~*!():@\\]*)+)? |
HTTP | \b(https?)://(?:(\S+?)(?::(\S+?))?@)?([a-zA-Z0-9\-.]+)(?::(\d+))?((?:/[a-zA-Z0-9\-._?,'+\&%$=~*!():@\\]*)+)? |
\b([a-zA-Z0-9%_.+\-]+)@([a-zA-Z0-9.\-]+?\.[a-zA-Z]{2,6})\b | |
Hostname | \b(?:[a-zA-Z0-9][a-zA-Z0-9\-]{0,61}?[a-zA-Z0-9]\.)+[a-zA-Z]{2,6}\b |
IP | \b(?:\d{1,3}\.){3}\d{1,3}\b |
IP with Optional Netmask | \b((?:\d{1,3})(?:/(\d{1,2}))?\b |
IP or Hostname | \b(?:(?:\d{1,3}|(?:[a-zA-Z0-9][a-zA-Z0-9\-]{0,6})\b |
上面的正则表达式实际书写时需把一个反斜杠替换成两个反斜杠,如匹配E-Mail时要写成
1
2
3
4
5
|
NSString
*regex = @
"\\b([a-zA-Z0-9%_.+\\-]+)@([a-zA-Z0-9.\\-]+?\\.[a-zA-Z]{2,6})\\b"
;
NSLog
(@
"Regex: %@"
,regex);
if
([@
"unmi@scalau.com"
isMatchedByRegex:regex]){
"Valid email address"
);
}
|
Regex: \b([a-zA-Z0-9%_.+\-]+)@([a-zA-Z0-9.\-]+?\.[a-zA-Z]{2,6})\b
Valid email address
这和Java的正则表达式一样,也就是要写成NSLog输出的样子,也就是转义的转义,如果是 \-或 \.编译时会提示:
Lexical or Preprocessor Issue Unknown escape sequence "\."
Lexical or Preprocessor Issue Unknown escape sequence "\-"
但执行时不会报错,只是匹配不成功.
记住,RegexKitLite的完全帮助手册尽在:http://regexkit.sourceforge.net/RegexKitLite/