Liad Goren
Liad Goren

Reputation: 319

Invalid regular expression: invalid group specifier name - a regex expression that breaks on any iOS device

let addCommas = (number) => {
        let [head, ...rest] = number.toString().split('.');
        rest.length === 0 ? rest = ['00'] : rest;
        return head.toString().replace(/\B(?<!\.\d*)(?=(\d{3})+(?!\d))/g, ",") + '.' + rest;
    }

the regex part breaks my code on any ios device. even on google chrome.

for the life of me, I couldn't understand why.

any thoughts and or ways I could go around this?

Upvotes: 2

Views: 2980

Answers (1)

Codesmith
Codesmith

Reputation: 6752

iOS has some bizarre issue, and refuses to support regex lookbehind (positive or negative).
And yes, apparently somehow it affects even Chromium on iPhone.
You're not alone:

Equivalent Regex Unsupported lookbehind assertion IOS Safari
How to make this regex safari / iOS compliant?
https://github.com/interscript/interscript-js/issues/10
https://github.com/twopluszero/next-images/issues/55

Just spent the last hour discovering this issue myself...

Upvotes: 4

Related Questions