firasdib / Regex101

This repository is currently only used for issue tracking for www.regex101.com
3.28k stars 199 forks source link

Javascript regex only allow ascii group names #1738

Open PoulBak opened 2 years ago

PoulBak commented 2 years ago

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 commented 2 years ago

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

firasdib commented 2 years ago

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 :)

PoulBak commented 2 years ago

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 ?

firasdib commented 2 years ago

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

PoulBak commented 2 years ago

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

firasdib commented 2 years ago

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

PoulBak commented 2 years ago

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

firasdib commented 2 years ago

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.