Regex to replace hyphens between two numbers with commas

Questions about XML that are not covered by the other forums should go here.
bee123
Posts: 5

Regex to replace hyphens between two numbers with commas

Thu Dec 22, 2016 2:25 pm

Hi there,

I have a text with numbers in between, the numbers should change from 9-3 into something like 9,3.
I can find the numbers with \d{1,2}[\*\-]{1}\d{1,2}
but how do I do the replacement?

Thanks for your help!
Radu
Posts: 5376

Re: Regex to replace hyphens between two numbers with commas

Thu Dec 22, 2016 2:36 pm

Hi,

You need to create groups using ( and ) for the text which will stay in place and then in the replace field use $1, $2, etc for the groups you want to keep.
So if you search for (\d{1,2})[\*\-]{1}(\d{1,2}) you can replace with $1,$2.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
bee123
Posts: 5

Re: Regex to replace hyphens between two numbers with commas

Thu Dec 22, 2016 2:40 pm

Thank you!

Return to “General XML Questions”

Who is online

Users browsing this forum: No registered users and 0 guests