A very simple one for someone that knows the answer. I’m working in EditPat Lite, and have a list in the format:
"Origin - Destination 1234.5 miles"
I need to insert a ‘,’ between the destinations and distances, and can identify the place to insert using ( [0-9]+.[0-9]+ miles). But I know not how to insert the comma. Have searched for solutions using various brackets, but nothing works. I need to prevent the strings being replaced by the regular expression.
Grateful for any tips.
You will need a regexp replacement function, which I suppose you have. In it, you can refer to matched expressions (as the other answer says, this is normally done with
$0or\0, or different numbers for sub-matches.You can either replace the regexp you have with
,\0, which means “a comma, followed by the thing that is being replaced”, or you can use a non-consuming match, so you replace the 0-character string just before the regexp with a comma:(?= [0-9]+.[0-9]+ miles)matches this “empty” string.This type of match is called “positive lookahead”. It’s also available in negative and lookbehind flavours:
(?!...),(?<=...),(?<!...).