php-simple-html-dom-parser
php-simple-html-dom-parser copied to clipboard
Escape minus char in regular expressions
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.
Still an issue over a year later