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

Escape minus char in regular expressions #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mlocati
Copy link
Contributor

@mlocati mlocati commented Oct 5, 2018

In PHP 7.3, PCRE2 (the library that parses regular expressions) has been upgraded to version 10.32.

It seems that this new version of PCRE is a bit more picky when parsing regular expressions.
For example, /^[\w-:]+$ is not accepted anymore, we have this error (see https://3v4l.org/vD5O2):

Compilation failed: invalid range in character class at offset 4

The reason? - is used to represent range of characters when in square brackets (for example: [A-Z] represents a character from A to Z).
And PCRE now interprets [\w-:] as any character from \w to :, which doesn't make sense (so the error is thrown).

The solution? Just escape - with \ to tell PCRE that we actually want the character -, and not a range of characters.

@zanderwar
Copy link

Still an issue over a year later

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.

2 participants