这是我要使用的表达方式。它可以在其他地方使用,例如regexr.com,但不能在VSCode中使用...
font\-size\:\s{0,1}\d{2,2}px\;\s{0,1}
这是HTML:
https://codepen.io/JashoowellPadderssonn/pen/WNbVVEq
我也尝试禁用所有无效的扩展。这是我的VSCode设置:
https://gist.github.com/CrocodileInAWhileAlligatorLater/409f0d9d179955ff80419a8a4506a09d
您只应转义需要转义的字符。
采用
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), \
и |
.
在字符类内部,必须始终对这些字符进行转义:]
和\
。在-
必须进行转义,如果它不位于字符类(的开头或结尾[-0-9_]
= [0-9_-]
= [_\-0-9]
),并且^
当在字符类开始表示文字必须进行转义^
([^0]
(比其他任何字符匹配0
)!= [\^0]
(匹配^
或0
) )。请参见在正则表达式中必须转义哪些特殊字符?。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句