正则表达式从具有至少一个数字的文本中提取所有单词

Regex to extract all words from text that have a least one number

如何匹配多行文本块中至少有一个 digit/number 的所有单词?我发现这个 Regular expression for a string that must contain minimum 14 characters, where at minimum 2 are numbers, and at minimum 6 are letters,它适用于单个字符串。我得到了前瞻的概念,但在我的场景中没有,因为我做了 preg_match_all()。有什么提示吗?

您可以使用此正则表达式搜索其中至少包含一个数字的所有单词:

\b\w*?\d\w*\b

要使其安全使用 unicode:

/\b\w*?\p{N}\w*\b/u

RegEx Demo

代码:

$re = '/\b\w*?\p{N}\w*\b/u'; 
preg_match_all($re, $input, $matches);