javascript 之正則匹配HTML

來源:互聯網
上載者:User

標籤:表達   ext   mic   amp   over   ima   orm   com   string   

Regex <(\S*?) [^>]*>.*?</\1>|<.*? />
匹配 <html>hello</html>|<a>abcd</a>
不匹配 abc|123|<html>ddd

 

Regex ^[^<>`~!/@\#}$%:;)(_^{&*=|‘+]+$
匹配 This is a test
不匹配 <href = | <br> | That‘s it

 

Regex &lt;!--.*?--&gt;
匹配 &lt;!-- &lt;h1&gt;this text has been removed&lt;/h1&gt; --&gt; | &lt;!-- yada --&gt;
不匹配 &lt;h1&gt;this text has not been removed&lt;/h1&gt;

 

Regex (\[(\w+)\s*(([\w]*)=(‘|&quot;)?([a-zA-Z0-9|:|\/|=|-|.|\?|&amp;]*)(\5)?)*\])([a-zA-Z0-9|:|\/|=|-|.|\?|&amp;|\s]+)(\[\/\2\])
匹配 [link url=&quot;http://www.domain.com/file.extension?getvar=value&amp;secondvar=value&quot;]Link[/li
不匹配 [a]whatever[/b] | [a var1=something var2=somethingelse]whatever[/a] | [a]whatever[a]

 

Regex href=[\"\‘](http:\/\/|\.\/|\/)?\w+(\.\w+)*(\/\w+(\.\w+)?)*(\/|\?\w*=\w*(&\w*=\w*)*)?[\"\‘]
匹配 href="www.yahoo.com" | href="http://localhost/blah/" | href="eek"
不匹配 href="" | href=eek | href="bad example"

 

Regex &quot;([^&quot;](?:\\.|[^\\&quot;]*)*)&quot;
匹配 &quot;This is a \&quot;string\&quot;.&quot;
不匹配 &quot;This is a \&quot;string\&quot;.

 

Regex (?i:on(blur|c(hange|lick)|dblclick|focus|keypress|(key|mouse)(down|up)|(un)?load|mouse(move|o(ut|ver))|reset|s(elect|ubmit)))
匹配
  onclick | onsubmit | onmouseover
不匹配 click | onandon | mickeymouse

 

Regex (?s)/\*.*\*/
匹配 /* .................... */ | /* imagine lots of lines here */
不匹配 */ malformed opening tag */ | /* malformed closing tag /*

 

Regex <(\S*?) [^>]*>.*?</\1>|<.*? />
匹配 <html>hello</html>|<a>abcd</a>
不匹配 abc|123|<html>ddd

 

Regex \xA9
匹配 ?
不匹配 anything

 

Regex src[^&gt;]*[^/].(?:jpg|bmp|gif)(?:\&quot;|\‘)
匹配 src=&quot;../images/image.jpg&quot; | src=&quot;http://domain.com/images/image.jpg&quot; | src=‘d:\w
不匹配 src=&quot;../images/image.tif&quot; | src=&quot;cid:value&quot;

 

Regex /\*[\d\D]*?\*/
匹配 /* my comment */ | /* my multiline comment */ | /* my nested comment */
不匹配 */ anything here /* | anything between 2 seperate comments | \* *\

 

Regex <[a-zA-Z]+(\s+[a-zA-Z]+\s*=\s*("([^"]*)"|‘([^‘]*)‘))*\s*/>
匹配 <img src="test.gif"/>
不匹配 <img src="test.gif"> | <img src="test.gif"a/>

javascript 之正則匹配HTML

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.