中文匹配:[\u4e00-\u9fa5]匹配单个字的中文

\s 匹配任意一个空白字符包括空格 \r\n

hello world there are four seasons in the year \b\w+\b 匹配每个单词
hello world there are four seasons in the year ^.*$ 匹配整个字符串

$%*&*sdfsd_ \W+(\w 匹配不了的它都能匹配) 如果[\w\W]+匹配任意字符 注意区别.+不能匹配任意字符,因为它不能匹配元字符.本身

①gr[ea]y  这个可匹配gray grey
②grey|gray 这个可匹配gray grey
③gr(a|e)y 这个可匹配gray grey,a e
④gr[a|e]y 这个可匹配gray grey gr|y

http://((?!archive).)*\s  链接中不包含archive的url

(?<=http).*?(?=url)这个是匹配上面一行,零宽先行和零宽后行,注意是零宽,=后面只是匹配条件,不获得匹配结果

 

<div id="zhengzhe"[^>]*>((?!<div).)*(((?'Open'<div[^>]*>)((?!<div).)*)+((?'-Open'</div>)((?!<div).)*)+)*(?(Open)(?!))</div>平衡堆栈正则

匹配下面

<div id="zhengzhe">
<strong>something</strong>
<div id="sdf">
<img />
hello world
</div>
<img />
</div>

注意:div标签里面不管嵌套多少都可以,但一定要对称,如果要匹配其他的对称标签之间的内容,就把标签换过来,你懂的