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?
Asked
Active
Viewed 1,432 times
3
1 Answers
3
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
RegEx Demo
Code:
$re = '/\b\w*?\p{N}\w*\b/u';
preg_match_all($re, $input, $matches);

anubhava
- 761,203
- 64
- 569
- 643
-
1yes this works good enough for me! thx thought it would be more complicated but forgot about word boundary – setcookie Jan 19 '15 at 13:17