2

I'm using the VSCode
enter image description here

Screenshot to demonstrate the search options I have selected: enter image description here

And here is the expression I'm trying to use. It works in other places, such as regexr.com, but not in VSCode...

font\-size\:\s{0,1}\d{2,2}px\;\s{0,1}

Here is the HTML:

https://codepen.io/JashoowellPadderssonn/pen/WNbVVEq

I have also tried disabling all extensions which did not work. Here are my VSCode settings:

https://gist.github.com/CrocodileInAWhileAlligatorLater/409f0d9d179955ff80419a8a4506a09d

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563

1 Answers1

5

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 as), \ и |.

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?.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • 1
    This is excellent work. I've verified that it's working using a variety of other expressions. Kudos. I must admit, I am a bit confused in that they say it's "more strict" because this seems a bit easier now that I know about Unicode properties, but I can picture what they mean. – CrocodileInAWhileAlligatorLate Feb 03 '20 at 23:04