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
  • 669,327
  • 51
  • 454
  • 560
Oleg Gordiichuk
  • 14,647
  • 5
  • 57
  • 94

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
  • 127,136
  • 16
  • 45
  • 63
2

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
  • 48,339
  • 8
  • 43
  • 63
2

Copy the capture group to the result. Replace

^(.*?),

with

$1
Barmar
  • 669,327
  • 51
  • 454
  • 560