Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php regex: find inline javascript in HTML document

Tags:

regex

php

i need to find inline javascript with php regex. I can find external script, but not inline, can anybody help me?

Here is my pattern for external:

"/<script(.*?)src(.*?)>(.*?)<\/script\s*>/smi"

Any ideas?

like image 557
Simon Avatar asked May 02 '26 05:05

Simon


1 Answers

"/<script((?:(?!src=).)*?)>(.*?)<\/script>/smix"

(My first look-ahead regex ;))

Please note that you should not parse HTML with regexes, see:

https://stackoverflow.com/a/1732454/221213

like image 187
KARASZI István Avatar answered May 03 '26 18:05

KARASZI István



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!