开发者

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜