Search code examples
regexregexp-replace

Regex Logic - replace commas between two numbers with dots


Hello there can i have an hint about how should i write the regex code to search for the commas (,) in those values between the |'...'| pattern? i need to find the commas and replace with dots(.) , if there's a comma in there of course.

|'2,3'|;|'5,6'|;|'2,1'|;|'3'|;|'6,5'|;|'9'|;|'7'|;|'4,4'|;|'4'|;|'1,1'|

expected result:

|'2.3'|;|'5.6'|;|'2.1'|;|'3'|;|'6.5'|;|'9'|;|'7'|;|'4.4'|;|'4'|;|'1,1'|

the pattern can be also what i will write below depending on some input parameters that i am going to receive in my method:

|'2,3'|,|'5,6'|,|'2,1'|,|'3'|,|'6,5'|,|'9'|,|'7'|,|'4,4'|,|'4'|,|'1,1'|

expected result:

|'2.3'|,|'5.6'|,|'2.1'|,|'3'|,|'6.5'|,|'9'|,|'7'|,|'4.4'|,|'4'|,|'1.1'|

this why i need a pattern for this because i don't know if i will receive the string with (;) or (,) separating the values

thanks so much


Solution

  • Regex Pattern

    Here is the pattern that you can use to search for the commas , between two numbers

    (?<=[0-9]),(?=[0-9])
    

    Regex Demo