Page 1 of 1

RegEx find using \1 across 1 or more lines

Posted: Wed Nov 19, 2003 5:02 pm
by Frogster
Using POSIX compliant setting, I am able to find multiple instances of a given item within a line by the use of () and \1, but if I attempt to do this across multiple lines (by adding $ or \n in, as appropriate) it does not seem to work. For example:

SAMPLE TEXT:

A treeefaaall creates an opeeening.
But threee trees remain.

Find within line:
([aeiou]{3})[^\1]+\1
This works as expected, and finds the 2x eee in the first line.

Find across lines, version a:
([aeiou]{3})[^\1]+\n[^\1]+\1
This is reported as an "Invalid regular expression"...

Find across lines, version b:
([aeiou]{3})[^\1]+$[^\1]+\1
This does not generate an error message, but it does not find the expected text.

Is there a way to effectively find multiple instances of the same string across multiple lines without "hard-coding" them into the find expression repeatedly?

THANKS!!
Dave

Posted: Wed Nov 19, 2003 5:14 pm
by Bob Hansen
Just a quick thought, no testing done:

:idea: Can you:
1. Temporarily replace \n with another unique character(s),
2. Run your RegEx, and then
3. Replace the unique character(s) with \n?

I usually use tilde (~) or multiple letter q strings (qqq) for the unique character(s).

Posted: Fri Nov 21, 2003 4:29 pm
by Frogster
Yeah, I guess I can do that but it is really limiting to have to do so. Guess I'll make a couple of macros for \n->~~ and ~~->\n (or something) to streamline a bit, but I'd have to check for presence of ~~ in each file first...

It would really be so much more convenient (and in my mind SENSIBLE!) to be able to use \1 across more than one line for finds!!

Just yesterday I had to create another work-around when using \1 in consecutive line finds would have worked perfectly and efficiently!

I guess I could go perl on this, but I really find the immediate feedback of TextPad to be much more useful for adapting & adjusting the work as needed.

Cheers!
Dave