Dear forum,
I need to remove commas from numbers and leave commas between words, but I can’t find regular expression that does this. Numbers are always same without whitespace characters, but text can be different (with whitespace characters on both side, on left, on right side of comma, or without white spaces) like:
one,two
tree , four
five, six
seven ,eight
Can please somebody help me with this.

    Just because you could:

    $string = preg_replace('#(?<=\d),(?=\d)#', '', $string);
    

    🙂

      I'm not certain, but I think these would remove commas from alphanumeric words too which may not be desired: "U2,2good"

        sneakyimp;10978221 wrote:

        I'm not certain, but I think these would remove commas from alphanumeric words too which may not be desired: "U2,2good"

        Yep. But then we don't really know the context for the OP's question, so who knows? 🙂

        But if that's an issue, you could try:

        $string = preg_replace('#\b(\d+),(\d+)\b#', "$1$2", $string);
        
          Write a Reply...