Simon
Simon

Reputation: 43

php regex: find inline javascript in HTML document

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?

Upvotes: 3

Views: 2968

Answers (3)

KARASZI Istv&#225;n
KARASZI Istv&#225;n

Reputation: 31467

"/<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

Upvotes: 4

Thariama
Thariama

Reputation: 50832

You need to find all those cases where inline script can be used (i.e. all listener functions onClick, onBlur, onMouseDown, onMouseUp, on...)).

Upvotes: 2

Vadym
Vadym

Reputation: 5284

"/<script[^\>]*>(.?)<\/script>/si"

Upvotes: 0

Related Questions