I am trying to reformat a string to my desired format. I have been trying to figure this out for a while but I can't think of any elegant solution using regexs. I have come up with a solution using String's indexOf() and replace() but it's not exactly pretty.
I want to convert any string so that there is exactly one space on each side of the "-".
Possible inputs:
"abc- abc"
"abc -abc"
"abc - abc"
"abc-abc"
and each case should be converted to
"abc - abc"
Thanks for any help. Let me know if you need more clarification.