[thelist] Escaping Parenthesis in RegExp

Chris Spruck cspruck at mindspring.com
Sat Mar 9 14:45:01 CST 2002


At 09:35 PM 3/8/02 -0800, Robert Goodyear wrote:
>In UltraEdit's RegExp syntax, the ^ is used to escape, but when using tagged
>expressions it all goes haywire, for example in the following string,
>
>This is a test of (123) in a replacement.
>
>If I want to change "(123)" to "Number:123", the RegExp...
>
>Find: ^(^(???^)^)
>Replace: Number:^1
>
>...completely blows up. I've tried using the backslash for escaping, too, and
>that doesn't work. I believe the Tagged Expressions are what's causing the
>problem, as UE uses ^( and ^) to delimit a tagged exp, which is identical to
>what an escaped special character should look like.
>
>-Robert Goodyear

Robert,

I took a look at UltraEdit since I had a local copy and found an option
which will help make this a LOT easier. Go to the Advanced menu, select
Configuration, click the Find tab, and check the checkbox for Unix style
Regular Expressions. Even with doing that, UE seems to have an incomplete
implementation of regex, so check out the help from the find dialog for all
the operators and some examples.

This expression    \((\d\d\d)\)    will find your string and you can then
replace it with Number:\1.

The \ escapes the ( around your number, then the second ( is what groups
for the replace backreference. The \d grabs any single digit, (so you need
three of \d, since UE regex doesn't let you define the number of instances
you want any other way), then the ) closes the replace backreference, then
\) closes the ) around your number.

Hope this helped!

Chris




More information about the thelist mailing list