I have used a replace macro for over a year in textpad 4. Textpad 5 did not understand the new macro. So i re-recorded it. The macro does the following:
1) Presses Ctrl Home
2) Types "#language: c\n#olddir: /\n#newdir: /\n"
3) Replaces ^\(.+\)\([0-9]+)$ with \10\t\1\2 note, \10 is \1 followed by a 0.
4) Saves the file.
When i undo all my changes and run the macro, steps 1, 2, and 4 occur, but not step 3.
Textpad 5: Replace Macro No longer works
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
I don't know about your problem running the macro. But...
For your replacement expression to make sense you must be using standard (as opposed to Posix) regular expression syntax (because your marking parentheses are backslashed). This being so, there is an error in your regular expression: the second close parenthesis should be backslashed:
^\(.+\)\([0-9]+\)$
But this doesn't make sense. It will match any line containing at least two characters, the last of which is a digit. The .+ will match maximally; so it will match all characters on the line except the last (because [0-9]+ has to match at least one character). The [0-9]+ will then just have the last character (a digit) to match. So it's equivalent to
^\(.+\)\([0-9]\)$
And it will replace
xyz123
with
xyz120\txyz123
Is that what you want?
[ I'll be away now until Friday. ]
For your replacement expression to make sense you must be using standard (as opposed to Posix) regular expression syntax (because your marking parentheses are backslashed). This being so, there is an error in your regular expression: the second close parenthesis should be backslashed:
^\(.+\)\([0-9]+\)$
But this doesn't make sense. It will match any line containing at least two characters, the last of which is a digit. The .+ will match maximally; so it will match all characters on the line except the last (because [0-9]+ has to match at least one character). The [0-9]+ will then just have the last character (a digit) to match. So it's equivalent to
^\(.+\)\([0-9]\)$
And it will replace
xyz123
with
xyz120\txyz123
Is that what you want?
[ I'll be away now until Friday. ]
I won't comment on the regex I'll leave that to ben_josephs.
I did have an issue where my macros would not run anymore and I could not ( apparently) record new ones after going to V5.0
The fix was to press F8, which brought up the search and replace dialogue box, then run the recorded macro.
My macros, which are mainly search and replace macros, are all working now.
hope this helps
John
I did have an issue where my macros would not run anymore and I could not ( apparently) record new ones after going to V5.0
The fix was to press F8, which brought up the search and replace dialogue box, then run the recorded macro.
My macros, which are mainly search and replace macros, are all working now.
hope this helps
John
I won't comment on the regex I'll leave that to ben_josephs.
I did have an issue where my macros would not run anymore and I could not ( apparently) record new ones after going to V5.0
The fix was to press F8, which brought up the search and replace dialogue box, then run the recorded macro.
My macros, which are mainly search and replace macros, are all working now.
hope this helps
John
I did have an issue where my macros would not run anymore and I could not ( apparently) record new ones after going to V5.0
The fix was to press F8, which brought up the search and replace dialogue box, then run the recorded macro.
My macros, which are mainly search and replace macros, are all working now.
hope this helps
John
-
- Posts: 5
- Joined: Wed Mar 21, 2007 3:21 pm
Yes, i did have a bug in the expression i submitted. The expresion i used was formatted correctly ( i did have a backslash on the last paren).
Now having the search window up before i run the macro, it does work. I recorded a new macro that had the "F8" to open the replace window before doing the replace. This did not help.
I do the standard format (not posix) as i learned regular expressions with textpad 4 default options.
The expresion ^\(.+\)\([0-9]+\)$ will match anything up to the last set of numbers at the end of the line. The numbers at the end of the line (multiple digits) will go into match 2, the remaining part of the line will go into match 1.
MyFile.cpp@@/main/branch/12
goes to the following with the replacement \10\t\1\2
MyFile.cpp@@/main/branch/0\tMyFile.cpp@@/main/branch/12
This is Rational Clearcase syntax to look at the different versions of the file on the branch /main/branch.
Thanks for the workaround of opening the replace window. And thank you for the help with the regular expression. I need to reread my posts before posting an expression to make sure i have it correct
Now having the search window up before i run the macro, it does work. I recorded a new macro that had the "F8" to open the replace window before doing the replace. This did not help.
I do the standard format (not posix) as i learned regular expressions with textpad 4 default options.
The expresion ^\(.+\)\([0-9]+\)$ will match anything up to the last set of numbers at the end of the line. The numbers at the end of the line (multiple digits) will go into match 2, the remaining part of the line will go into match 1.
MyFile.cpp@@/main/branch/12
goes to the following with the replacement \10\t\1\2
MyFile.cpp@@/main/branch/0\tMyFile.cpp@@/main/branch/12
This is Rational Clearcase syntax to look at the different versions of the file on the branch /main/branch.
Thanks for the workaround of opening the replace window. And thank you for the help with the regular expression. I need to reread my posts before posting an expression to make sure i have it correct
No it won't. As ben_josephs explained to you, .+ will match greedily. It will consume as much of the input as allowed, leaving the [0-9]+ to match only one digit. You need to use either non-greedy matches (which I don't believe TextPad supports), or make your expression smarter, such as ^([^0-9]+)([0-9]+)$fred_kidd_iv wrote:The expresion ^\(.+\)\([0-9]+\)$ will match anything up to the last set of numbers at the end of the line. The numbers at the end of the line (multiple digits) will go into match 2, the remaining part of the line will go into match 1.
-
- Posts: 5
- Joined: Wed Mar 21, 2007 3:21 pm
Yes. I see the problem now. I have not run into the problem with my regular expression because at most, i have 3 versions per branch. But the one time i get more then that, it will have a problem.
I will work on making a better expression that will match just what i need. For now though, i am just happy that my textpad macro will use the replace with the replace window upen, as some of my changes touch 70 files or more (only 2 versions each. version 0 and version 1).
Thanks again for the work around.
I will work on making a better expression that will match just what i need. For now though, i am just happy that my textpad macro will use the replace with the replace window upen, as some of my changes touch 70 files or more (only 2 versions each. version 0 and version 1).
Thanks again for the work around.
-
- Posts: 5
- Joined: Wed Mar 21, 2007 3:21 pm
Thanks again for pointing out my replace expression was incorrect. I had a chance to look at it more and found one that works (i have swapped to POSIX):
^(.+/)([0-9]+)$
By adding the /, i make sure it grabs all of the numbers at the end. So this:
Fred Kidd IV[/list][/list]
^(.+/)([0-9]+)$
By adding the /, i make sure it grabs all of the numbers at the end. So this:
- /vobs/vob_name/subdir/MySourceFile.cpp@@/main/my_branch_name/12
- /vobs/vob_name/subdir/MySourceFile.cpp@@/main/my_branch_name/0\t/vobs/vob_name/subdir/MySourceFile.cpp@@/main/my_branch_name/12
Fred Kidd IV[/list][/list]