Page 1 of 1

Help with tagged regular expressions

Posted: Mon Aug 19, 2002 12:35 pm
by Kevin Hein
I'm having a problem using tagged regular expressions while using find/replace.

Here is my problem: It doesn't seem to work.

Here is an example (contrived) data file:

bob
bob
bobrobbob
hello bob

Here is the search and replace dialog:

Find expression: \([bob]+\)
Replace expression: \1 dude

Expected output after search/replace runs:

bob dude
bob dude
bob dude robbob dude
hello bob dude

But - when I try to run the search/replace it gives me the following error:

Cannot find regular expression: \([bob]+\)

I checked the help and all the examples under regular expressions and everything looks right. I even looked under all the configuration "stuff" that I could find to see if this was something that needed to "turned on" and I couldn't find anything.

I'm using version 4.5.0 : 32-bit Edition on Windows 2000

Is this a bug or am I doing something wrong?

Thanks for the help

Kevin

Re: Help with tagged regular expressions

Posted: Mon Aug 19, 2002 2:29 pm
by Sam
Find: (bob)
Replace: \1 dude

Produces the correct output given in your sample.

The original regex fragment "[bob]+" looks suspicious... "[bo]+" is equivalent... matching bo, bob, bobo, bb, ooo, bobobob, etc.

Re: Help with tagged regular expressions

Posted: Mon Aug 19, 2002 3:02 pm
by Kevin Hein
Huh - interesting. The TextPad here is the information from TextPad help in regards to tagged expressions:

<begin quote>
A tagged expression is an RE that starts with the pair \( and ends with the pair \). There can be up to nine such expressions in a complete RE. Such an expression matches the same as the expression without the surrounding \( and \). The first expression defined in this way can be referenced as \1 later in the RE, and so on up to \9 for the ninth tagged expression. Each such reference matches the same string as its original tagged expression. For example \(tu\) \1 matches the string "tu tu".
<end quote>

Thanks for your help

Kevin

Re: Help with tagged regular expressions

Posted: Tue Aug 20, 2002 11:15 am
by Andreas
Wether it is \(\) or () depends on the Posix setting
on the configure-Preferences-Edit page

[bob]: [] matches any character in the [].
so [bo] is equivalent to [ob] or [bob] or [bbo] or [oob] or ...

[bob]+ then matches b, bb, bbb, ... or o, oo, ooo, oooo ... or ob obo obb obbb ...
i.e. any string that consists of any number (greater than 1) of os and bs.

To match bob and tag it, use \(bob\) or (bob) depending on the posix setting.