Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我是这个常规 exp 概念的新手。我正在尝试使用这个 reg ex
[^@\s]+$
如果我将字符串指定为“abs”,则它实际上不包括字符 's' 。这意味着 '\s' 被读取为字符 's' 而不是空格。请帮我解决这个问题
您可以使用此 POSIX 等效项:
^[^@[:space:]]+$
[:space:]匹配任何空格,包括换行符。如果您想避免匹配换行符,请改用:[:blank:]。
[:space:]
[:blank:]
POSIX 中的空格字符类是[:space:],因此在您的情况下,您的正则表达式将是:
[^@[:space:]]+$
请注意,[:space:]不能[]像\d或\s其他口味一样独立。单独的空格字符类必须在里面[]:
[]
\d
\s
[[:space:]]