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: 6
Joined: Thu Dec 22, 2016 2:22 pm

Regex to replace hyphens between two numbers with commas

Post by bee123 »

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: 9434
Joined: Fri Jul 09, 2004 5:18 pm

Re: Regex to replace hyphens between two numbers with commas

Post by Radu »

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: 6
Joined: Thu Dec 22, 2016 2:22 pm

Re: Regex to replace hyphens between two numbers with commas

Post by bee123 »

Thank you!
Post Reply