Regular expressions and replacing

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
Bart

Regular expressions and replacing

Post 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
Ed

Re: Regular expressions and replacing

Post by Ed »

It works OK for me with TP 4.5
mo

Re: Regular expressions and replacing

Post by mo »

Use "Replace Next" when that happens.
Stephan

Re: Regular expressions and replacing

Post 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
Bart

Re: Regular expressions and replacing

Post 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
Post Reply