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

feat: allow regexp for the pattern #147

Closed
RodrigoEspinosa opened this issue Apr 3, 2021 · 3 comments
Closed

feat: allow regexp for the pattern #147

RodrigoEspinosa opened this issue Apr 3, 2021 · 3 comments

Comments

@RodrigoEspinosa
Copy link

Summary

The patter attribute needs to be a string. However, some editors (like in a brand new VSCode) will automatically detect "unnecessary" scapes in strings and remove them, making it harder to send those as strings.

For instance, this ^[:alnum:]+\@[:alnum:\.]\:(\/[:alnum:]+)*$ will be saved as ^[:alnum:]+@[:alnum:.]:(/[:alnum:]+)*$ automatically.

As a workaround, we can do something like /^[:alnum:]+\@[:alnum:\.]\:(\/[:alnum:]+)*$/.toString() and then remove the first and last /, but it would be nice if we can send the regular expression from the beginning.

handle('pattern', ['string'], (pattern) => {

@ChALkeR
Copy link
Contributor

ChALkeR commented Aug 20, 2021

I don't understand.

What is wrong with ^[:alnum:]+@[:alnum:.]:(/[:alnum:]+)*$?

Additional escaping is needed for / in literal regexps only.
I.e.:

> /a\/b/.source === new RegExp('a/b').source
true

Could you share an example that has behavior (i.e. validation) differences?

@ChALkeR
Copy link
Contributor

ChALkeR commented Aug 20, 2021

If . is supposed to be a dot (and not any char), ^[:alnum:]+@[:alnum:\.]:(/[:alnum:]+)*$ should be encoded as "^[:alnum:]+@[:alnum:\\.]:(/[:alnum:]+)*$" as a string, for example.

@RodrigoEspinosa
Copy link
Author

Thanks for the clarification, @ChALkeR!

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

No branches or pull requests

2 participants