Eliminating Characters using PHP PCRE
If I have a string $random, and I want to throw o开发者_运维百科ut everything except commas and numbers, how could I do this in PHP PCRE?
I know \d
will match numbers, but I don't get the rest of PCRE.
Try something like
preg_replace("/[^\d,]/", "", $random);
You can use T-Regx (you don't even need delimiters):
pattern('[^\d,]')->remove($random)->all();
or if you want only to remove the first
pattern('[^\d,]')->remove($random)->first();
精彩评论