标签:re
metacharacters relation to match:
*:0-multi
+:1-multi
?:0-1
{n},{n,m},{n,}:the number of matching
string switch
eg: pattern="lynn|coco"
src1="hello,my name is lynn"
result1="lynn"
src2="hello,my name is coco"
result2="coco"ignore case
eg:pattern="(?i)Lynn"
src="hello,my name is lynn"
result="lynn"
multi-repeat-character
eg:pattern="n{2}"
src="hello,my name is lynn"
result="nn"
digital match
eg:pattern="\d+"
src="I am 24 years old but 18 years in school"
result="24","18"
eg:pattern="[0-9]+"
src="I am 24 years old but 18 years in school"
result="24","18"
optional character match
eg:pattern="colou?r"
src1="color" result=color
src2="colour" result=colour
本文出自 “Fighting” 博客,请务必保留此出处http://lynnhome.blog.51cto.com/3654477/1408810
标签:re
原文地址:http://lynnhome.blog.51cto.com/3654477/1408810