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

Replace [\w\W] with [\s\S] and [0-9] with \d in regexes #1107

Merged
merged 3 commits into from
May 8, 2017
Merged

Replace [\w\W] with [\s\S] and [0-9] with \d in regexes #1107

merged 3 commits into from
May 8, 2017

Conversation

valtlai
Copy link
Contributor

@valtlai valtlai commented Mar 7, 2017

[\w\W]  →  [\s\S]
  [0-9]  →  \d

@valtlai valtlai changed the title Replace [\w\W] with [^] and [0-9] with \d in regexes Replace [\w\W]/[\s\S] with [^] and [0-9] with \d in regexes Mar 7, 2017
@Golmote
Copy link
Contributor

Golmote commented Mar 7, 2017

Wow, I actually didn't know about the [^] shortcut. Although it sounds clever, I'm afraid it might be less clear than the more usual [\s\S] and [\w\W] variants.
I'm perfectly ok with replacing [0-9] with \d though.

What's your opinion about this @LeaVerou, @zeitgeist87 ?

@LeaVerou
Copy link
Member

LeaVerou commented Mar 7, 2017

I'm fine with it :)

@zeitgeist87
Copy link
Collaborator

According to https://regex101.com/ the [^] regex works only with the Javascript flavor. It doesn't work in Python, Go or PHP. I don't know how accurate that is and I haven't actually tested it with different regex engines. It seems to be a pretty obscure trick though. Maybe we should take that into consideration...

@Golmote
Copy link
Contributor

Golmote commented Mar 8, 2017

@zeitgeist87, I agree. @valtlai, would you mind updating this PR to use one of [\s\S] or [\w\W] (we could definitely uniform all occurrences to one of those choices) to match any character, instead of [^] which might lead to confusion?

@valtlai valtlai changed the title Replace [\w\W]/[\s\S] with [^] and [0-9] with \d in regexes Replace [\w\W] with [\s\S] and [0-9] with \d in regexes Mar 8, 2017
@valtlai
Copy link
Contributor Author

valtlai commented Mar 8, 2017

@Golmote Yeah, done.

@Golmote Golmote merged commit 8aa2cc4 into PrismJS:gh-pages May 8, 2017
@Golmote
Copy link
Contributor

Golmote commented May 8, 2017

Thanks for contributing!

Golmote added a commit that referenced this pull request May 8, 2017
gflohr added a commit to gflohr/prism that referenced this pull request May 5, 2018
Golmote pushed a commit that referenced this pull request May 10, 2018
* support for Template Toolkit 2

* optimized quoted string regexes

* optimized double-quoted string regex

* fully qualified tt2 plug-in names don't work

Also use \w.

* do not use empty character class

See #1107.

* put keyword tests in alphabetical order

* ordered tt2 keywords alphabetically

* removed redundant operator rule for tt2

* removed possibly existing old rules before inserti

* indentation

* allow backslash in front of lf in tt2 strings

* indentation

* avoid backtracking

* escape xml special characters

* indent with tab instead of spaces

* greedy is no longer needed for variables

Also use \w instead of explicit character class.

* re-generated with gulp
@valtlai valtlai mentioned this pull request Sep 27, 2021
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

Successfully merging this pull request may close these issues.

4 participants