Macro's Replace All Only Replaces First Occurrence
Posted: Tue Jul 08, 2008 4:25 pm
Windows XP SP 2, TextPad 5.2.0.
I have a macro with two steps.
The first step deletes all lines that do not match a regular expression.
The second step then attempts a replace, where there are multiple occurrences to replace.
The problem lies in the second step.
During macro recording, the replace operation successfully finds and replaces all occurrences of the "Find what" expression; however, during macro playback, it only finds and replaces the first occurrence.
To replicate:
Create the following file, call it dummy.txt:My goal: to remove every line that doesn't begin with an "a", and then to put a newline after every remaining "x".
Record the following macro (keystrokes in grey italics, things to type in blue bold, my comments after "//" in green):
But if you play the macro back on the original dummy.txt, you will instead see
The recording/playback discrepancy seems related to the combination of the macro's two steps; a macro made up of step 2 alone plays back fine.
Helios, is this a bug? Is there a workaround that doesn't involve two separate macros?
Thanks,
Art Metzer
I have a macro with two steps.
The first step deletes all lines that do not match a regular expression.
The second step then attempts a replace, where there are multiple occurrences to replace.
The problem lies in the second step.
During macro recording, the replace operation successfully finds and replaces all occurrences of the "Find what" expression; however, during macro playback, it only finds and replaces the first occurrence.
To replicate:
Create the following file, call it dummy.txt:
Code: Select all
0
12
abcdxefxxgh
*$4
zzRecord the following macro (keystrokes in grey italics, things to type in blue bold, my comments after "//" in green):
- F5 // Step 1, remove each line not beginning with "a"
alt+I
^a
alt+M // 1.1. Bookmark each line that starts with an "a"
Esc
alt+S // 1.2. Invert bookmarked lines
A
alt+E // 1.3. Delete lines now bookmarked (i.e., not starting with "a")
L
B
F8 // Step 2, put a newline after every x
alt+I
x // 2.1. Find each "x"...
alt+P
&\n // 2.2....to be replaced by "x" plus newline
alt+A // 2.3. Replace All
Esc
Code: Select all
abcdx
efx
x
ghCode: Select all
abcdx
xefxxghHelios, is this a bug? Is there a workaround that doesn't involve two separate macros?
Thanks,
Art Metzer