Greedy Group problem

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
plugge
Posts: 2
Joined: Mon Nov 22, 2010 3:30 pm
Location: Maryland

Greedy Group problem

Post by plugge »

I'm making a global change to my source file. I have a macro to make the changes, however I'd like to attempt using a regular expressions. I'm having issues with the syntax, however.

I want to simply replace all my functions with the exact same line followed by an added subroutine.

original:
---
function xyz
---
replaced with:
---
function xyz
statistics_routine
---

I can match the function and linefeed alright, but the first group match (\1) simply returns the exact string -- "\1" rather than the match. I did switch to POSIX format, but that didn't help.

My fields are

find:
^function.*\n
replace:
\1\nstatistics_routine

Thanks in advance,
dgp
dgp
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Find what: ^function.*
Replace with: \0\nstatistics_routine

[X] Regular expression

Replace All
or
Find what: ^(function.*)
Replace with: \1\nstatistics_routine

[X] Regular expression

Replace All
or similar.

The second of these assumes you are using "Posix" regular expression syntax:
Configure | Preferences | Editor

[X] Use POSIX regular expression syntax
plugge
Posts: 2
Joined: Mon Nov 22, 2010 3:30 pm
Location: Maryland

Post by plugge »

I got bit by the zero based index -- ouch.

Thanks, that worked like a charm.

dgp
dgp
Post Reply