regex: find one-digit number

前端 未结 4 2052
温柔的废话
温柔的废话 2020-12-10 13:24

I need to find the text of all the one-digit number.

My code:

$string = \'text 4 78 text 558 my.name@gmail.com 5 text 78998 text\';
$pattern = \'/ [\         


        
4条回答
  •  天涯浪人
    2020-12-10 14:13

    Use word boundaries. Note that the range quantifier {1} (a single \d will only match one digit) and the character class [] is redundant because it only consists of one character.

    \b\d\b
    

提交回复
热议问题