1

I have a issue with regex pattern. It replace not only "," but also all characters that are before.

I would like to replace first occurrence of the "," to ".":

"1,,000.23" -> "1.,000.23"

This pattern I am using now :

^(.*?),

Result that I receive is :

"1,,000.23" -> ".,000.23"

Expected result :

"1,,000.23" -> "1.,000.23"
Barmar
  • 741,623
  • 53
  • 500
  • 612
Oleg Gordiichuk
  • 15,240
  • 7
  • 60
  • 100

3 Answers3

3

Maybe you could use ^([^,]+), and replace with $1.

This will capture from the beginning of the string ^ not a comma in a group ([^,]+) and then match a comma ,

The fourth bird
  • 154,723
  • 16
  • 55
  • 70
3

Use ^(.*?), and replace it with $1.. This means:

group as less as possible things from line start till first , into group 1
then match a `,` 
and replace it with the captured text of group 1 `$1` and a dot `.`

See: https://regexr.com/3kjdq

Patrick Artner
  • 50,409
  • 9
  • 43
  • 69
2

Copy the capture group to the result. Replace

^(.*?),

with

$1
Barmar
  • 741,623
  • 53
  • 500
  • 612