Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use more inclusive regexp for matching file paths #227

Closed
kauffj opened this issue Nov 25, 2019 · 5 comments
Closed

Use more inclusive regexp for matching file paths #227

kauffj opened this issue Nov 25, 2019 · 5 comments

Comments

@kauffj
Copy link

kauffj commented Nov 25, 2019

Per this discussion over on lbry-desktop: lbryio/lbry-desktop#2777 (comment)

As long as you are in ES2018 or later land, you can use the capture group \p{L} to represent all letters and \p{N} all numbers. So you could use this (untested) regexp instead:

/^[\p{L}\p{N}_@()-][\p{L}\p{N}_.@()-\s]+.(jpeg|jpg|png|bpm|webp)$/

@btzr-io
Copy link
Owner

btzr-io commented Nov 26, 2019

Not supported in Firefox and Edge

Despite being a part of the standard since 2018, unicode proeprties are not supported in Firefox (bug) and Edge (bug).

There’s XRegExp library that provides “extended” regular expressions with cross-browser support for unicode properties.

Alternative: https://github.com/slevithan/xregexp

@btzr-io
Copy link
Owner

btzr-io commented Nov 26, 2019

Looks like we can use this syntax directly with :
https://github.com/josephfrazier/babel-plugin-transform-xregexp

@btzr-io
Copy link
Owner

btzr-io commented Nov 26, 2019

It should be like this:

/^[\p{L}\p{N}_@()-]+[\p{L}\p{N}_.@()-]+.(jpeg|jpg|png|bpm|webp)$/u

@btzr-io
Copy link
Owner

btzr-io commented Nov 26, 2019

Actually this is the correct regex with the unicode support:

const regexImage = new RegExp(
/(^[\p{L}\p{N}*@()_-]([\p{L}\p{N}\s.*@()_-]+)?)+.(jpeg|jpg|png|bpm|webp)$/
)

Fixed by 8419754

@btzr-io
Copy link
Owner

btzr-io commented Nov 26, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants