正则表达式单词匹配

Nic*_*eon 2 .net regex

如何在文化独立的方式匹配单词而不是字母?

\w匹配单词或数字,但我想忽略数字.所以,"111或这个" \w\s将无法正常工作.

我想只得到"或者这个"?我想{^[A-Za-z]+$}这不是解决方案,因为德语字母表有一些额外的字母.

Ode*_*ded 5

这适用于匹配单词:

\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)