Anyone knows how to use regular expression to replace ",/d" with just the number "/d"? I tried using /d and it wouldn't work...it would replace the , followed by whatever number with the alphabet character "d".
Thanks in advance.
Anyone knows how to use regular expression to replace ",/d" with just the number "/d"? I tried using /d and it wouldn't work...it would replace the , followed by whatever number with the alphabet character "d".
Thanks in advance.
You capture what you want to keep and use it in the replacement:
s/,(\d)/$1/;
Just remove any comma that precedes a number, using a look-ahead:
s/,(?=\d)//
If you tried s/,\d/\d/
, Perl would view the replacement as a double quoted string. As there is no escape code \d
, the backslash is simply ignored, and d
used.
If you want to substitute the match with a part of the match, you have to use captures (see ysth's answer).
My above substitution doesn't include the digit in the matched string, therefore just substituting the comma with the empty string (i.e. deleting it), but still asserts that the comma is followed by a digit.