RE question...

General questions about using TextPad

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

Post Reply
Jason

RE question...

Post by Jason »

Hi...

I have a RE questions...

I am trying to use RE on SEARCH > FIND in FILES...

1. I want to find if there is any match for two blank lines and ABCDEF in third line withn all my text files... I tried '\n\nABCDEF' and it doesn't work...

2. Is there any way I could do search and replace for multiple files???

Thank you...
Have a nice day!!!

Jason
Andreas

Re: RE question...

Post by Andreas »

Use a Textpad with no files opened.

Do the search in Files for
^ABCDEF
Ok, this might list more files than needed (i.e. those that have lines beginning with ABCDEF but not an empty line before them), but we come to this later.
Now open all these files (Context menu on Search Results -> Open All)

Now do a Replace operation:
Search for:
\n\nABCDEF
(this now takes care of the empty line before the line starting with ABCDEF)

Replace By
whateveryouwantgoeshere

Make sure RE is on. In the scope box select "All Documents"

Then gently click on "Replace All"

Do a "Save All" to save all the changed files.
Jason

Re: RE question...

Post by Jason »

Thank you Andreas...

That worked!!! It takes one more unexpected step to do the job but it works...
Let me ask you this then...
How can I get two blank lines from multiple files???
I typed \n\n for Find in Files, and I got the error message saying 'Cannot search files for a regular expression including '\n'...
Any idea how to do this???

Thanks... Have a nice day...

Jason
Andreas

Re: RE question...

Post by Andreas »

Almost the same principle:
Find in files:
^$
gets a list of all files containing at least ONE empty line.
Now replace
\n\n\n
(yes, THREE \n, see note below) by
\n
to remove two consecutive empty lines.

Note
\n\n finds only ONE blank line except at the beginning of the file.
Every line has a \n at its end, \n\n finds the one at a possibly not empty line plus one following immediately ...

Another note:
when trying to replace multiline Regex in combination with a Find in Files:
Do the Find in Files with the most restrictive line of your multiline Regex (i.e. the line that will probably find the smallest amount of files).
Then open all the files.
Then do the Replacing using your multiline Regex on all active documents.
Jerry

Re: RE question...

Post by Jerry »

Try this

^\n\nABCDEF

The ^ looks for a new line at the beginning of the line, which will find two blank lines and then the text. It will find it even it it is at the beginning of the file.
Roy Beatty

Re: RE question...

Post by Roy Beatty »

In some situations you might need to rtrim (remove "[ \t]+$") to get empty lines.

Andreas, Jerry -- very cool replies -- Roy
Jason

Re: RE question...

Post by Jason »

Thank you Andreas, Jerry, and Roy...

Somehow I am still having trouble getting empty lines with ^$... I get nothing with ^$ as a search term... So... what I did was do the search for the possible combination of same lines for all files and open all the results and find \n\n instead...(Of course I had to do the same job for a*.txt b*.txt ...) :(
Why doesn't Find in Files take \n??? :(
Roy... can you tell me some more on your expression??? I don't understand what you have there and the result are way weird to explain...

Thank you guys and have a nice day!!!

Jason
Roy Beatty

On Nothingness

Post by Roy Beatty »

Re: [ \t]+$<br>
See the first item in the TextPad Help file topic: "Examples: Finding Text."

Blank lines might not be empty. They might contain any combination of spaces and tabs. "^[ \t]*$" (note the *), finds all blank lines, empty or not. "^$" finds empty lines only. Replacing "^[ \t]*$" with <null> will turn all blank lines into empty lines (^$). If you get no hits, then your blank lines were already empty. I hope this makes "nothing" more understandable. ;-)

> I get nothing with ^$ as a search term<br>
Open the Find (not Replace) dialog and enter ^$ as your pattern. Hit the Mark All button. The appropriate lines *do* get bookmarked. (If your object is to remove the empty lines you can then Edit > Delete > Bookmarked Lines.)

Now try doing a Find Next (not replace) for ^$ on your file containing empty lines. The cursor moves to the first instance of ^$. Hit Find Next again. Nothing happens; the cursor stays put. Most people expect the cursor to move to the next blank line. If there are 4 empty lines in the file, you should get a "Can not find" message on the fifth press of the Find Next button.

This is, well, a minor bug. The beta testers might have had a hard time discovering this bug since there is nothing to highlight. Then again, the developers may have documented somewhere that the search for the next instance of the regex pattern begins at the point just *after* the current instance of the pattern. That position is *before* the new-line character (\n). So the next instance of this infinitesimal pattern is found again in the same spot.

The help file says \n "should only be used to match text that spans line boundaries." But when you wish to move to the next empty or blank line, I recommend searching for "\n\n" or ""\n^[ \t]*\n". That will force highlighting of (at minimum) the next end-of-line marker and moves the cursor unambiguously to where you expect it.

And remember, if your Replace text has fewer \n than Find, then you will remove lines with each Replace Next.

-----------------
You never knew that there could be this much ado about nothing!

HTH,
Roy
Post Reply