NogDog;10896661 wrote:I'll need to see a reference or proof before I'll worry about that, since (a) the manual says that \d matches any decimal digit and I'm only aware of 10 such digits, plus (b) it's never yet failed me. (Possibly there could be issues if scanning multi-byte unicode text, perhaps?)
Ask and thou shalt receive 😉
$str = 'this is text 123²4³5 this is more text...';
preg_match_all('#\d+#', $str, $matches);
echo '<pre>'.print_r($matches[0], true);
Output:
Array
(
[0] => 123²4³5
)
Note the exponents being matched as well..
Now granted, in this situation that the OP is looking for, I would doubt an encounter with exponents.. so yes, in general, \d is deemed safe enough. But one of these days, someone will use \d when it WILL match more than merely 0-9, and they will scratch thier heads wondering why.. so just as a force of habit, (more often than not.. but not all the time), I tend to explicitly use [0-9].
I have not actually timed the speed difference between the two methods in matching say the above text in a 10,000 time repeating loop.. but I wouldn't be surprised if [0-9] edges out \d, just for that simple reason (that \d as a character class checks for slightly more characters...
EDIT - ..Oops.. the above string would not make a good comparison.. stript out all the exponents and then compare [0-9] vs \d would be more fair 😉