0
在這種情況下:如何讓正則表達式忽略HTML標籤之間的內容?
<script>
function();
</script>
please don't touch me.
<script>
function();
</script>
我試圖捕捉標記和它們之間的信息,而不是「請不要碰我在中間」。到目前爲止,我想出了這一點:
/<script>[^]+<\/script>/ig
從最初的<script>
標籤捕捉一切到最後</script>
標籤。
用正則表達式一般解析HTML是一個壞主意。請參閱:http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags/1732454#1732454 – Skogsv