Regular Expressions 101

Community Patterns

Isolate javascript elements within [html] text

0

Regular Expression
PCRE2 (PHP >=7.3)

/
(<script\b[^><]*>)(.*?)(<\/script>)|\bon\w+\s*=\s*\K(?|(\")([^\"]+)\"|(')([^']+)')
/
isg

Description

Needed to find all content between <script>...</script> tags, plus any content within a < tag > that has an argument starting with on, e.g. <span onClick='abc'>

See https://onlinephp.io/ for PHP runtime

Submitted by anonymous - a year ago (Last modified a year ago)