Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

REGEX working in chrome but breaks in safari

The following javascript regex breaks in safari getting SyntaxError: Invalid regular expression: invalid group specifier name"

/^(?!\s)[A-Za-z0-9\'\.\-\,\s]*(?<!\s)$/.test('ABCD@#');

Can someone please help me to re write the regex which can work in safari?

I find out that safari doesn’t support lookbehind but still not able to re write the whole regex which can be good for safari.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Modify your pattern to avoid the negative lookbehind. Since you seem to want a non whitespace character as the last character, just use a character class for that.

/^(?!\s)[A-Za-z0-9'.,\s-]*[A-Za-z0-9'.,-]$/.test('ABCD@#')

Side note: your current pattern looks wrong for what you are trying to match.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading