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
Regular expressions and replacing
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
-
Stephan
Re: Regular expressions and replacing
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
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
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
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