Use standard assertions if possible
RunDevelopment opened this issue · 1 comments
RunDevelopment commented
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$/mRunDevelopment commented
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.