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.
Asked
Active
Viewed 157 times
1

Wiktor Stribiżew
- 607,720
- 39
- 448
- 563

Shejo284
- 4,541
- 6
- 32
- 44
1 Answers
1
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.

Wiktor Stribiżew
- 607,720
- 39
- 448
- 563
-
Thanks :-). I think I understand it now. – Shejo284 Nov 13 '16 at 22:37