PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, November 20, 2022

[FIXED] how to define regex (preg_replace) to removes space between number character

 November 20, 2022     php, preg-replace, regex, space, string     No comments   

Issue

I have string like this:

$str = "old iccid : 809831 3245 345 new iccid : 999000 112221"

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";

i've tried to use this syntax:

$output = preg_replace( '/\d[ *]\d/', '', $str);

but didn't work well.


Solution

Try:

$output = preg_replace('/(?<=\d)\s+(?=\d)/', '', $str);


Answered By - xdazz
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing