2
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?

Liad Goren
  • 299
  • 1
  • 4
  • 18
  • This is definitely a valid regular expression and it works in the latest Chrome and Firefox Nightly. Which version of Chrome are you using? – Sebastian Simon Mar 18 '21 at 07:28
  • First of all, thanks :) secondly, this code was uploaded to my prod environment - so various versions of chrome on various versions of IOS but I've also ran this on an iPhone 11 Pro Max - with its latest updates on a chrome with the latest version and still, it crashed. I also ran an emulator (lambdatest) with iphone 11 pro max on a chromium browser and it in fact crashed. SO... I'm totally confused. – Liad Goren Mar 18 '21 at 07:35

1 Answers1

4

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...

Codesmith
  • 5,779
  • 5
  • 38
  • 50