0
我如何定義一個正則表達式,只是讓我喜歡正則表達式匹配文本htmltag文本htmltag模式
文本HTMLTag文本HTMLTag文本HTMLTag模式........
基本單位patter是'text HTMLTag',可以使用$ 1和$ 2獲取。
的一個實例數據將
abarelixx is a sample data for spellchecking<img src="Randomz" alt="Randomz Image">Randomz is the name of the image</img>Bigboss<img src="Randomz" alt="Randomz Image">Randomz is the name of the image</img>this is another text string
這需要被分解爲文本HTMLTag ......如果沒有文字/ HTMLTag,它應該返回「」。
有''標籤?不要使用正則表達式來解析HTML。雖然你可以使用正則表達式進行標記,但它仍然可能[很難正確標記HTML](http://stackoverflow.com/questions/9462104/remove-on-js-event-attributes-from-html-tags/9466152# 9466152)。 – Qtax 2012-02-29 08:04:06
不,沒有像''這樣的東西; 'img'是一個空標籤。 Nishant,你能澄清一下你想要什麼,或許還有其他例子嗎? – beerbajay 2012-02-29 08:13:05
JavaScript能夠遍歷DOM。無論你在哪裏使用正則表達式,然後使用childNodes數組。例如,你的上面是5個節點(圖像節點有自己的孩子,假設他們不是圖像,而是這是有效的HTML)。 – Matt 2012-02-29 14:56:13