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?
Finding Text on Multiple Lines
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
Re: Finding Text on Multiple Lines
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.
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.
Re: Finding Text on Multiple Lines
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.
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.
Re: Finding Text on Multiple Lines
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!
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!
Re: Finding Text on Multiple Lines
Thank you! That helped my problem. I hope that in the next version it is
possible to search multiple \n characters.
possible to search multiple \n characters.
- Realicity.com
- Posts: 3
- Joined: Sun Feb 01, 2009 4:06 pm
- Location: Minneapolis, Minnesota
- Contact:
Thanks for the post.
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.
- webber123456
- Posts: 50
- Joined: Wed Jul 30, 2003 2:55 am
Re: Finding Text on Multiple Lines
[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.
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.
Re: Finding Text on Multiple Lines
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.Roy Beatty wrote: Did anybody actually understand this set of instructions ?
If so, please post them in English with complete sentences.
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:
A Posix RE for this might take two steps:Mikko Vatanen wrote: procedure foo1;
begin
something;
end;
procedure foo2;
begin
something;
something_else;
end;
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...