regex: find one-digit number

前端 未结 4 2055
温柔的废话
温柔的废话 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:12

    Search around word boundaries:

    \b\d\b
    

    As explained by the others, this will extract single digits meaning that some special characters might not be respected like "." in an ip address. To address that, see F.J and Mike Brant's answer(s).

提交回复
热议问题