I am working on a project that i use regex for input formatting.I use lookbehind but safari doesn't support it. So i decided to use different regex for safari. I checked the browser and decide which regex should i use using the code below.
const isSafari = /^((?!chrome|android).)*safari/i.test(navigator.userAgent)
let regexes
if (!isSafari) {
regexes = {
numbersAndFirst: /^0*(?=.)|[^\d|,]|(?<=,(.*)),|(?<=,.*0)0*$/g,
}
} else {
val = val.split('').reverse().join('')
regexes = {
numbersAndFirst: /^0*(?=0.)|[^\d|,]|,(?=(.*),)|(?=.*)0*$/g,
}
}
But when this code block runs, safari throws SyntaxError: Invalid regular expression: invalid group specifier name. I tried to use try-catch but result is same. Is there a way to solve this?
Aucun commentaire:
Enregistrer un commentaire