Page 1 of 1

Greedy Group problem

Posted: Mon Nov 22, 2010 3:40 pm
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

Posted: Mon Nov 22, 2010 3:59 pm
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

Posted: Mon Nov 22, 2010 4:13 pm
by plugge
I got bit by the zero based index -- ouch.

Thanks, that worked like a charm.

dgp