Shejo284
Shejo284

Reputation: 4771

Texwrangler replacement string

I would like to use the reqex expression: \s\.\d to find a expression, e.g., ".9" and replace it with the expression "0.9", i.e., part of the search pattern is part of the replacement pattern. This is to avoid replacing .TRUE. with 0.TRUE. I've tried replacement patterns such as 0.\d but this just puts a "d" in the replacement string.

Upvotes: 1

Views: 159

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 627119

You may use & as a backreference to the entire match. If you want to match a dot preceded with a non-word char and followed with a digit, you may use \B\.\d and replace with 0&.

However, if you use \s\.\d and want to add a zero, you would need a capturing group - (\s)(\.\d) and replace with \010\2 (where \01 is the backreference to the first capturing group, 0 is a zero and \2 is the backreference to the second capturing group. Note that this approach won't let you match at the string start, you will need to add an alternative in the first group: (^|\s)(\.\d) where ^ matches the start of string/line.

Upvotes: 1

Related Questions