这适用于匹配单词:
\b[^\d\s]+\b
Run Code Online (Sandbox Code Playgroud)
分解:
\b - word boundary
[ - start of character class
^ - negation within character class
\d - numerals
\s - whitespace
] - end of character class
+ - repeat previous character one or more times
\b - word boundary
Run Code Online (Sandbox Code Playgroud)
这将匹配任何由单词边界分隔的内容,特别是排除数字和空格(因此"aa?aa!aa"之类的"单词"将匹配).
或者,如果您也想要排除这些,您可以使用:
\b[\p{L}\p{M}]+\b
Run Code Online (Sandbox Code Playgroud)
分解:
\b - word boundary
[ - start of character class
\p{L} - single code point in the category "letter"
\p{M} - code point that is a combining mark (such as diacritics)
] - end of character class
+ - repeat previous character one or more times
\b - word boundary
Run Code Online (Sandbox Code Playgroud)