3

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?

Community
  • 1
  • 1
setcookie
  • 549
  • 1
  • 6
  • 11

1 Answers1

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
  • 713,503
  • 59
  • 514
  • 593
  • 1
    yes 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