Finding Text on Multiple Lines

General questions about using TextPad

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

Post Reply
POC

Finding Text on Multiple Lines

Post by POC »

TP v4.5
Perhaps I'm not doing it right, but I am having trouble finding text that is on multiple lines. For example, from the text example below:

---
1 Quantity Payment for SEO, US 149.00
Invoice: SEO01405
---

... I wish to search for the following text throughout the document:

---
1 Quantity Payment for SEO, US 149.00
Invoice:
---

I have tried using the following string in the "Find" box to try to find this string :

---
1 Quantity Payment for SEO, US 149.00\nInvoice:
---

... where \n should signify a new line. But this does not work. Does textpad support this?

I've noticed that I also cannot locate blank empty lines using find either, in the same way I can find a tab. To find a tab, I would highlight a tab and control-c, then paste that into the find box, which would appear as a small block. Shouldn't a blank line be findable in this same way as well?
Jens Hollmann

Re: Finding Text on Multiple Lines

Post by Jens Hollmann »

You are right! You have to turn on "regular expression" on finding this or otherwise \n will not be a linebreak but the literal string (backslash n). Then it should work.

Searching for empty lines is interesting. Again search for a regular expression!

"\n\n" finds (more or less) the empty lines. This will mark the line-ends though and you need two cursor movements to place the curso in this empty line. If this is not annoying to you, go ahead.

"^$" will find the next empty line without marking anything because there is nothing to mark (the line is empty after all) and the cursor is neatly in the empty line. But this will not jump to the next empty line if you are already in one! So you have to move the cursor to the next not empty line and then this will find the next empty one. Can be annoying too.

By the way: "\n[[:blank:]]*\n" and "^[[:blank:]]*$" will find empty lines that may contain spaces or tabs but nothing else.
Mikko Vatanen

Re: Finding Text on Multiple Lines

Post by Mikko Vatanen »

What if I want to find two words with n-lines beetween them?

For example:

procedure foo1;
begin
something;
end;

procedure foo2;
begin
something;
something_else;
end;

and I want to find all lines from "procedure" to "end". So that
first search gives me first procedure and second the second.
Roy Beatty

Re: Finding Text on Multiple Lines

Post by Roy Beatty »

An expedient is to Find all \n and replace with a string known not to exist in the text, eg, ~1~. Doing so will convert the text into one long text string. Put a ~1~ at the start of the string. Then you can <br>
Find:::: ~1~~1~procedure .+~1~end;<br>
to select all of the text between "procedure " and "end;". To stick a form feed before each procedure<br>
Replace: \f&<br>
Finally, replace all ~1~ with \n

Viola!
Mikko Vatanen

Re: Finding Text on Multiple Lines

Post by Mikko Vatanen »

Thank you! That helped my problem. I hope that in the next version it is
possible to search multiple \n characters.
User avatar
Realicity.com
Posts: 3
Joined: Sun Feb 01, 2009 4:06 pm
Location: Minneapolis, Minnesota
Contact:

Thanks for the post.

Post by Realicity.com »

I have been using TextPad for almost 10 years and this is one of the things I have wondered from time to time, but never took the time to figure out.
James Svoboda
Realicity in Minnesota
Minneapolis Search Marketing
User avatar
webber123456
Posts: 50
Joined: Wed Jul 30, 2003 2:55 am

Re: Finding Text on Multiple Lines

Post by webber123456 »

[quote="Roy Beatty"]An expedient is to Find all \n and replace with a string known not to exist in the text, eg, ~1~. Doing so will convert the text into one long text string. Put a ~1~ at the start of the string. Then you can <br>
Find:::: ~1~~1~procedure .+~1~end;<br>
to select all of the text between "procedure " and "end;". To stick a form feed before each procedure<br>
Replace: \f&<br>
Finally, replace all ~1~ with \n

Viola![/quote]

Did anybody actually understand this set of instructions ?

If so, please post them in English with complete sentences.

Thanks.
Evil Bob
Posts: 3
Joined: Sat Feb 14, 2009 3:10 am

Re: Finding Text on Multiple Lines

Post by Evil Bob »

Roy Beatty wrote: Did anybody actually understand this set of instructions ?

If so, please post them in English with complete sentences.
What he said was, replace all newlines "\n" with a unique token, like ~1~, so that you can put the newline back afterwards... This will make your entire file one line of text, which bypass's the problem.

One of the drawbacks to this though, is that with large files, everything being on one line really slows down processing. Where possible, try to leave the chunks you need to search on a separate lines... ie, if you know where the start of a search is, put in an exception...

Data:
Mikko Vatanen wrote: procedure foo1;
begin
something;
end;

procedure foo2;
begin
something;
something_else;
end;
A Posix RE for this might take two steps:

find:::^(procedure.+)$
replace:::~1~\1

find:::\n([^~].+)$
replace:::~2~\1


Results:
~1~procedure foo1;~2~begin~2~something;~2~end;

~1~procedure foo2;~2~begin~2~something;~2~something_else;~2~end;


You can then do your multi-line search on the results, and replace the tokens ~1~ and ~2~ with newlines when you are done.

Hope this helps...
Post Reply