在正则表达式范围内使用 \d
Using \d in regex range
在 neovim (v0.5.0) 中,正则表达式 \d
匹配输入字符串中的任何数字。正则表达式 [0-9]
做同样的事情,但 [\d]
而是匹配文字 d
字符,如这些图像所示:
是否可以在这样的字符范围内使用 \d
,还是我必须键入 [0-9]
?
在POSIX bracket expression([...]
)中,\d
不能用于匹配数字。
但是,在 POSIX 括号表达式中,您可以使用 POSIX character classes. Neovim supports 很多,但在您的情况下,您可以使用 [:digit:]
。因此,要匹配逗号或数字,您可以使用 [,[:digit:]]
.
在 Neovim 中,您可以 切换到方括号内的 an NFA regex engine that supports shorthand character classes。
Vim will automatically select the right engine for you. However, if you run
into a problem or want to specifically select one engine or the other, you can
prepend one of the following to the pattern:
\%#=0
Force automatic selection. Only has an effect when
'regexpengine' has been set to a non-zero value.
\%#=1
Force using the old engine.
\%#=2
Force using the NFA engine.
因此,您可以在模式前面加上 \%#=2
后使用 [\d]
。
在 neovim (v0.5.0) 中,正则表达式 \d
匹配输入字符串中的任何数字。正则表达式 [0-9]
做同样的事情,但 [\d]
而是匹配文字 d
字符,如这些图像所示:
是否可以在这样的字符范围内使用 \d
,还是我必须键入 [0-9]
?
在POSIX bracket expression([...]
)中,\d
不能用于匹配数字。
但是,在 POSIX 括号表达式中,您可以使用 POSIX character classes. Neovim supports 很多,但在您的情况下,您可以使用 [:digit:]
。因此,要匹配逗号或数字,您可以使用 [,[:digit:]]
.
在 Neovim 中,您可以 切换到方括号内的 an NFA regex engine that supports shorthand character classes。
Vim will automatically select the right engine for you. However, if you run into a problem or want to specifically select one engine or the other, you can prepend one of the following to the pattern:
\%#=0
Force automatic selection. Only has an effect when
'regexpengine' has been set to a non-zero value.
\%#=1
Force using the old engine.
\%#=2
Force using the NFA engine.
因此,您可以在模式前面加上 \%#=2
后使用 [\d]
。