I would like to read everything JavaScript out of a string with preg_match_all
.
$pattern = '~<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>~su';
$success = preg_match_all($pattern, $str, $matches, PREG_SET_ORDER);
array(0 => '<script>alert("Hallo Welt 1");</script>');
The result now contains the script tag as well. I would like to exclude this tag.
My Sample Online Regex with Sample Code.