I have the following string:
Input:
$str = "I want to remove only comma from this string, how ?";
I want to remove commas from $str
, I'm new in programming and I don't understand how regex works.
I have the following string:
Input:
$str = "I want to remove only comma from this string, how ?";
I want to remove commas from $str
, I'm new in programming and I don't understand how regex works.
Regex: (?<!\d)\,(?!\d)
(\,|\.)
for matching exact either ,
or .
(?!\d)
should not contains digits ahead.
(?<!\d)
should not contains digit behind.
PHP code:
<?php
$str = "I want to remove only comma from this string, how. ? Here comma and dot 55,44,100.6 shouldn't be removed";
echo preg_replace("/(?<!\d)(\,|\.)(?!\d)/", "", $str);
Output:
I want to remove only comma from this string how ? Here comma 55,44,100 shouldn't be removed