You should only escape the characters that need to be escaped.
Use
font-size:\s?\d{2}px;\s?
Note the -
(here), :
and ;
are not special and thus MUST NOT be escaped.
The reason for it is that the regex is now compiled with the u
modifier enabling Unicode property classes to work (e.g. \p{L}
matches any Unicode letter). Here is a VSCode Github issue, Consider searching with JS regexes in unicode mode. It was closed on September 3, 2019 and verified on October 3, 2019.
The side effect is that there are more strict requirements to escaping.
Outside of character classes, [...]
, the following chars must be escaped: .
, ^
, $
, *
, +
, ?
, (
, )
, [
, {
(you may leave it unescaped in the majority of cases, however, if you need to find {
followed with a number and then }
escaping becomes required, cf. /a\{3}/
(matches a{3}
) != /a{3}/
- matches three a
s), \
и |
.
Inside character classes, these chars must ALWAYS be escaped: ]
and \
. The -
must be escaped if it is not located at the beginning or end of the character class ([-0-9_]
= [0-9_-]
= [_\-0-9]
), and ^
must be escaped when at the character class start denoting a literal ^
([^0]
(matches any char other than 0
) != [\^0]
(matches ^
or 0
)). See What special characters must be escaped in regular expressions?.