正则表达式:单词边界

Regex: word boundaries

我必须搜索包含大写字母或数字的词。

我使用 \b[^ ]*[A-Z0-9]+[^ ]*\b,但是我想使用 [^\b] 而不是 [^ ],但这会选择所有短语...

ThisisSometext, that has s0me</code><strong><code>nUm8ers, likeBoeing-380 orRNA-78.Thatis GREAT!

您可以使用 \w* 来匹配零个或多个单词字符。

\w*[A-Z0-9-]+\w*

\S*[A-Z0-9]+\S*

请注意,您不能在字符 class 中包含 \b\B。您可以通过其他一些方式在不将两者包含在字符 class 中的情况下获得结果。 \S* 匹配零个或多个非 space 字符。

DEMO