3

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?

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
Simon
  • 43
  • 1
  • 4

3 Answers3

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

KARASZI István
  • 30,900
  • 8
  • 101
  • 128
  • Yes, this is for all scripts, but I need the one, without src attribute in opening tag – Simon Sep 24 '10 at 15:30
  • cool this almost is correct :) You just need to add ? after first * : "/ – Simon Sep 24 '10 at 17:49
2

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

Thariama
  • 50,002
  • 13
  • 138
  • 166
  • No, i haev HTML doc ant i need to find text like but not – Simon Sep 24 '10 at 15:26
  • 1
    @no, there are enough ways to run JS. Another way: ``. A better solution would be whitelisting using an application like HTML Purifier. – Lekensteyn Sep 24 '10 at 15:28
0
"/<script[^\>]*>(.?)<\/script>/si"
Vadim
  • 5,154
  • 2
  • 20
  • 18