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 = \'/ [\
It really depends on where the numbers can appear and whether you care if they are adjacent to other characters (like . at the end of a sentence). At the very least, I would use word boundaries so that you can get numbers at the beginning and end of the input string:
$pattern = '/\b\d\b/';
But you might consider punctuation at the end like:
$pattern = '/\b\d(\b|\.|\?|\!)/';