Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
PCRE2 (PHP >=7.3)

/
(\/\/.*|\/\*[\s\S]*?\*\/)|((['"])(?:\\\3|\\?.)*?\3|`(?:\\`|\$({(?:(?1)|(?2)|(?4)|[\s\S])*?})|\\?[\s\S])*?`|\/(?:\\\/|\\?.)*?\/[gmixsuUAJD]*)
/
gm

Description

Matches comments, strings, templates, and regexes from javascript code. also matches templates recursively in order to correctly get template data

Submitted by ephf - a year ago