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

Re: Regex to replace hyphens between two numbers with commas

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

Re: Regex to replace hyphens between two numbers with commas

Post by bee123 » Thu Dec 22, 2016 2:40 pm

Thank you!

Post Reply