From time to time, I use Perl regular expressions with backreferences to make otherwise impossibly tedious global replacements. Today, I discovered a quirk in their behavior, at least in the context of the UltraEdit Find and Replace engine.
My original find and replace expressions were as follows.
Find What:
Replace With:
The resulting replacement value is, obviously, not what I expected.
It seems that the presence of the backslashes in the text, most of which were part of the replacement literal, confused the Find and Replace engine. This is how I solved it.
Find What:
Replace With:
There are changes in both expressions.
In retrospect, I realized that doubling the backslashes in the replacement string should have been enough. Reverting to saved, I repeated the test, making only that change. As I anticipated, the amended replacement expression, as follows, also produced the desired result.
Takeaway: When your replacement expression contains both literal backslashes and backreferences to capture groups from a regular expression in the Find What box, you must double the literal backslashes, or they will be interpreted as invalid backreferences, and eaten.
UltraEdit rocks!
My original find and replace expressions were as follows.
Find What:
Code: Select all
"C:\\DOCUME~1\\DAG\\MYDOCU~1\\PROGRA~1\\VISUAL~1\\EXE\\Console\\WWLOGGER\\_notes\\(.*?)\.LOG"
Code: Select all
..\Test_Data\\1.LOG
Code: Select all
..Test_Data\1.LOG
Find What:
Code: Select all
"C:\\DOCUME~1\\DAG\\MYDOCU~1\\PROGRA~1\\VISUAL~1\\EXE\\Console\\WWLOGGER\\_notes(\\.*?)\.LOG"
Code: Select all
..\\Test_Data\1.LOG
- I moved the terminal backslash on the search path string, just to the left of the capturing group, inside the parentheses, making it part of the group.
- I doubled all of the backslashes in the replacement string.
Code: Select all
..\Test_Data\WWLoggerRegularDrills.LOG
Code: Select all
..\\Test_Data\\\1.LOG
UltraEdit rocks!