RunDevelopment/eslint-plugin-clean-regex

Use standard assertions if possible

RunDevelopment opened this issue · 1 comments

Standard assertions \b, \B, ^, and $ are efficiently implemented and easy to understand. That's why they should be preferred over lookaround assertions which do the same.

Examples:

/foo(?!\w)/ => /foo\b/,
/foo(?!.)/ => /foo$/m

I did a small benchmark for the /foo(?!\w)/ => /foo\b/ case (and similar) and it seems like the regex engine is perfectly capable of optimizing the \b into (?!\w), so there is no performance overhead.