JS RE or why Atom fin-and-replace is broken

Oct 15, 2018  │  m. Jul 29, 2023 by manuhortet  │  #javascript  

Today, I had to edit some specific values of a not-that-big csv file, and instinctively tried to do it manually from Atom. After too many some tries, I concluded something was wrong. My regex was definitely on point, but Atom kept saying its Invalid regular expression thing.

I repeated my try, but this time from PyCharm, and… voilà!

But hey, wtf? Why are regex not working on Atom?

A simple search returned the answer: Javascript’s regular expression flavor is being used. I didn’t know the flavor nor its specialties which seem to be more than a just few, and didn’t manage to find any related info on the official Atom documentation.

What I found is that an issue about the missing documentation problem has already been opened in the official discuss . As the user @jeancroy summed up pretty good in that same discussion, the missing features on the JS’ regex flavor are:

    * No \A or \Z anchors to match the start or end of the string. Use a caret or dollar instead.
    * Lookbehind is not supported at all. Lookahead is fully supported.
    * No atomic grouping or possessive quantifiers.
    * No Unicode support, except for matching single characters with \uFFFF.
    * No named capturing groups. Use numbered capturing groups instead.
    * No mode modifiers to set matching options within the regular expression.
    * No conditionals.
    * No regular expression comments.
    * No /s modifier to make the dot match all characters, including line breaks.
More info about the flavor can be found in the official _regular-expression info index

Although missing lookbehind, atomic grouping or conditionals seems problematic for the find-and-replace utility of the editor, it seems there are not intention to change this any soon.

Nor I have to stop regexing from PyCharm.