Page 1 of 1

Regular expressions and replacing

Posted: Thu Oct 31, 2002 10:48 am
by Bart
Hi all,

I am using a regular expression to search for certain character combinations. That works fine.
But I want to extend the found text by adding extra characters before it and one after it. The found text itself remains unchanged.
So I thought I'd use the ampersand (&) in the Replacement box.
But this doesn't work because after replacement TextPad starts the next search at the beginning of the replaced text. And there it finds the search expression again! Result: a loop.
How do I get TextPad to start the next search at the end of the replaced text?

TIA,

Bart

Re: Regular expressions and replacing

Posted: Thu Oct 31, 2002 1:10 pm
by Ed
It works OK for me with TP 4.5

Re: Regular expressions and replacing

Posted: Thu Oct 31, 2002 1:52 pm
by mo
Use "Replace Next" when that happens.

Re: Regular expressions and replacing

Posted: Thu Oct 31, 2002 5:54 pm
by Stephan
Check the TextPad help on Regular Expressions.
You can capture the text that matches your regex - using \( and \) - and then use \1, \2 and so on as references. So, something like

NewText\1 more nre text \2 and still more new text

can be used in the repace text field to produce new text. Click "Replace Next" or "Replace All" to start replacing.

Hope that helped.

Stephan

Re: Regular expressions and replacing

Posted: Sat Nov 02, 2002 12:20 pm
by Bart
Ok, it seems to work when I use "Replace All".
Simple "Replace" and "Replace Next" don't since in those cases TextPad starts its next search in front of the replaced text and finds there again the already replaced serach text.
This is weird behaviour, so I'll report it as bug.

Thanks anyway!

Bart