Reputation: 629
How would I match all words that have at least one digit/number in multiline text block? I found this, Regular expression for a string that must contain minimum 14 characters, where at minimum 2 are numbers, and at minimum 6 are letters, which works for a single string. I get the concept of lookaheads, but not in my scenario since I make a preg_match_all()
. Any hints?
Upvotes: 3
Views: 1451
Reputation: 785196
You can use this regex for searching all words with at least a digit in it:
\b\w*?\d\w*\b
To make it unicode safe use:
/\b\w*?\p{N}\w*\b/u
Code:
$re = '/\b\w*?\p{N}\w*\b/u';
preg_match_all($re, $input, $matches);
Upvotes: 3