Using a negative look multiple times (or matching multiple characters with ^)?

I want to do something like this:

/<script[^>]*>(?!<\/script>)*<\/script>/g

to combine all script tags in an html string using javascript.

I know this will not work, but I cannot find any other solutions. script -tag can either use the src attribute, or close it immediately after ( <script src="..." type="text/javascript"></script>), or it can contain code in script -tag ( <script type="text/javascript">...</script>)

+3
source share
2 answers

You were close

/<script[^>]*>(?:(?!<\/script>).)*<\/script>/g

You should have something to eat the actual body of the script. What is doing here ..

, ( ) . script 1, (?:...), , @AlanMoore, .

+6

/<script[^>]*>.*?<\/script>/g

. .*? - , , .

+2

All Articles