如何定义正则表达式(preg_replace)以删除数字字符之间的空格 [英] how to define regex (preg_replace) to removes space between number character
本文介绍了如何定义正则表达式(preg_replace)以删除数字字符之间的空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这样的字符串:
$str = "old iccid : 809831 3245 345 new iccid : 999000 112221"
PHP 中如何定义正则表达式以去除数字字符之间的空格字符,成为该输出?
How to define regex in order to remove the space character between number character in PHP, to become this output?
$output = "old iccid : 8098313245345 new iccid : 999000112221";
我尝试使用这种语法:
$output = preg_replace( '/\d[ *]\d/', '', $str);
但效果不佳.
推荐答案
尝试:
$output = preg_replace('/(?<=\d)\s+(?=\d)/', '', $str);
这篇关于如何定义正则表达式(preg_replace)以删除数字字符之间的空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文