Regex101 icon indicating copy to clipboard operation
Regex101 copied to clipboard

Javascript regex only allow ascii group names

Open PoulBak opened this issue 3 years ago • 8 comments

Bug Description

This will fail on Regex101: /(?<æøå>a)\k<æøå>/ although javascript is unicode (and it does work in browsers).

Reproduction steps

Just test the above regex.

Expected Outcome

No errors.

Browser

Include browser name and version Edge 98

OS

Include OS name and version Windows 11

PoulBak avatar Mar 06 '22 17:03 PoulBak

Exactly the same when using .Net, which is 100% unicode.

PoulBak avatar Mar 07 '22 08:03 PoulBak

You're both right, and the reason for this is that the browser support for \p{Letter} is very lacking still, which means I cannot reliably match these strings. For that reason, they are currently limited to \w, but as browser support progresses, I will update this.

Unless you know of a good alternative way I can handle this :)

firasdib avatar Mar 07 '22 09:03 firasdib

Well the 'u' flag is not supported by old browsers either. Can't you simply make a test on page load if \p{Letter} is supported and if it is use that, otherwise use \w ?

PoulBak avatar Mar 07 '22 14:03 PoulBak

@PoulBak The trouble is that there are hundreds of regexes that will need to be re-written, and I will no longer be able to use regex literals (since they will be parsed and throw errors), which makes it even more complicated. Its a complex and ugly solution, but perhaps there is no better.

firasdib avatar Mar 07 '22 16:03 firasdib

May be a better option would be to have two versions of the regexes in two different files, which you can then load with ajax based on the unicode test you do. That way you can still have literal constructors, which is good for performance (and easier to write).

PoulBak avatar Mar 07 '22 16:03 PoulBak

@PoulBak Absolutely, but now we're entering "is it worth it"-territory, since the only benefit is having unicode in your group names (which extremely few people use).

firasdib avatar Mar 07 '22 17:03 firasdib

I have never liked false errors. May be you could simply disable the check. But of course it's your decision.

PoulBak avatar Mar 07 '22 17:03 PoulBak

It will remain until I find a better way. The alternative is to throw engine errors at the user and a blank screen when/if their browser does not support the syntax. Much worse in my opinion.

Vänliga hälsningar / Best regards,

Firas Dib

On 7 Mar 2022, at 18:24, PoulBak @.***> wrote:

 I have never liked false errors. May be you could simply disable the check. But of course it's your decision.

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you commented.

firasdib avatar Mar 07 '22 17:03 firasdib