Sanity Check on a RE Replace

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
User avatar
kengrubb
Posts: 324
Joined: Thu Dec 11, 2003 5:23 pm
Location: Olympia, WA, USA

Sanity Check on a RE Replace

Post by kengrubb »

I'm doing a RE Replace, and here are the results I get.

Scenario #1
Find what: \xFF
Replace with: \
Result: Replaces ÿ with \

Scenario #2
Find what: \xFF
Replace with: \\
Result: Replaces ÿ with \

Scenario #3
Find what: \xFF
Replace with: \\\\
Result: Replaces ÿ with \\

The Replace with value would seem to resolved from RE into a literal if it's a valid RE (Scenarios #2 and #3), but otherwise it's treated as a literal (Scenario #1).

I am guessing it has always been that way, but should it?
(2[Bb]|[^2].|.[^Bb])

That is the question.
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

When regular expression is selected, certain characters in the replacement expression (the "replacement format string") have special meanings.

TextPad's help, under Reference Information | Replacement Format Strings, states:
These format strings treat all characters as literals except for '$', '\', '(', ')', '?', and ':'. To output any of those characters as a literal, precede it with a '\'.
It would appear that, as a convenience to the user, if a backslash stands alone in a replacemnet expression (or is unpaired at the end of a replacemnet expression), so that it plainly is not quoting anything, it's treated as a literal. The alternative would be to treat it as an error and annoy the user.

Note that a replacement format string is not a regular expression.
Post Reply