php-simple-html-dom-parser icon indicating copy to clipboard operation
php-simple-html-dom-parser copied to clipboard

Escape minus char in regular expressions

Open mlocati opened this issue 5 years ago • 1 comments

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.

mlocati avatar Oct 05 '18 10:10 mlocati

Still an issue over a year later

zanderwar avatar Dec 18 '19 01:12 zanderwar