更新时间:2022-04-02 22:39:36
删除 []
并添加 \s *
每个左右(零个或多个空白字符) \ -
Remove the []
and add \s*
(zero or more whitespace characters) around each \-
.
此外,你不需要逃避 -
。 (你可以拿出 \
从 \ -
)
Also, you don't need to escape the -
. (You can take out the \
from \-
)
说明: [ABCA-Z]
是字符组的,它匹配 A
, b
, C
,或之间的任何字符 A
和以Z
。结果
这不是你想要做的事。
Explanation: [abcA-Z]
is a character group, which matches a
, b
, c
, or any character between A
and Z
.
It's not what you're trying to do.
在应对更新的正则表达式:
In response to your updated regex:
[ - \.\s]
到 [ - \.\s] +
来匹配任何这些字符中的一个或多个(例如, -
与它周围的空格>) \b
空格和(
。[-\.\s]
to [-\.\s]+
to match one or more of any of those characters (eg, a -
with spaces around it)\b
doesn't match the boundary between a space and a (
.