When looking at the accepted answer of stripping out all characters from a string, leaving numbers, the author added a +
after the expression
$str = preg_replace('/[^0-9.]+/', '', $str);
in order to find sub-strings, instead of single occurrences, to remove. For the functionality the +
is optional. But I started to wonder whether adding the +
is faster or not. (Or is there not any difference?)
I would assume it is faster, due to less string and memory handling. But I could also understand that more complex regex expressions are slower than simple ones.
So when using this technique to remove sub-strings should one try to find large or small sub-strings?