Text replace escaping with backslashes

The "Text Find/Replace" action seems to be using backslashes to escape with when it performs a replacement.

Eg: Replace "foo" with "f\ab" in this text: "food" -> "fbd".

In most cases you can work around this by doubling all your backslashes in advance, so you replace with "f\\ab" rather than "f\ab".

However, if the backslash is found in the search itself, I think it could make life very difficult.

There doesn't seem to be any reason they should be escaped in the replacement...$'s are used for subexpression references, not \'s.

 

Steve

On a similar note, I find the behaviour of % in the search pattern a bit confusing. It seems that variable references are always expanded, whereas there is an option not to expand them in the replacement text. This leads to an unintuitive situation where you want to replace every occurrence of % with %%: the search pattern is %% and the replacement pattern is %%. An option would be good.

Also, if anyone is looking at this action, I would love an explicit way to set variables to subexpressions. A simple improvement would be allowing you to replace to a different variable from the source. So you could have something like:
Source variable: source, which contains “foo foo 12345 boo”
Pattern: \d+
Save to: dest

End result: source is unchanged, but dest now contains 12345. (actually this wouldn’t really work if the source text featured the pattern more than once)

Even better would be allowing you to save multiple subexpressions to separate variables:
Source text: 2001-03-25 filename.txt,Comment comment foo
Pattern: ^(\d±\d±\d+) ([A-Za-z.]+),(.*)$
Save subexpression 1 to: Revdate
Save subexpression 2 to: Filename
Save subexpression 3 to: Comment

etc.

Steve