diff --git a/src/JS.php b/src/JS.php index c3712b5..b7be8d6 100644 --- a/src/JS.php +++ b/src/JS.php @@ -222,14 +222,16 @@ protected function extractRegex() return $placeholder; }; - $pattern = '\/[^=]*?(?getKeywordsForRegex($this->keywordsReserved, '/'); + $before = '([=:,;\)\}\(\{]|^|'.implode('|', $keywords).')\s*'; $after = '[\.,;\)\}]'; $methods = '\.(exec|test|match|search|replace|split)\('; - $this->registerPattern('/'.$pattern.'(?=\s*('.$after.'|'.$methods.'))/', $callback); + $this->registerPattern('/'.$before.'\K'.$pattern.'(?=\s*('.$after.'|'.$methods.'))/', $callback); // 1 more edge case: a regex can be followed by a lot more operators or // keywords if there's a newline (ASI) in between, where the operator