End of File symbol

General questions about using TextPad

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

Post Reply
redcairo
Posts: 39
Joined: Fri May 06, 2011 6:34 am

End of File symbol

Post by redcairo »

I finally found a reference to "end of file" being slash z. ( /z ) I thought, with the use of that, that I could insert some text into lots of files at the same time, and have it be put in at the end of file.

It doesn't work at all. I'm thinking I got something wrong. The code? Is doing search/replace like to search for that, then add text plus replace that after the text, a problem? Are there any suggestions?

Many thanks in advance.
User avatar
kengrubb
Posts: 324
Joined: Thu Dec 11, 2003 5:23 pm
Location: Olympia, WA, USA

Post by kengrubb »

End of File, or EOF, is a concept or process--not a character.

Where did you find the reference to slash Z being EOF?
(2[Bb]|[^2].|.[^Bb])

That is the question.
redcairo
Posts: 39
Joined: Fri May 06, 2011 6:34 am

Post by redcairo »

Well, obviously I was looking at something not applicable, which is just embarrassing. But it was this page

http://superuser.com/questions/427514/w ... nd-of-file
User avatar
kengrubb
Posts: 324
Joined: Thu Dec 11, 2003 5:23 pm
Location: Olympia, WA, USA

Post by kengrubb »

SE is a strange and wonderful place
(2[Bb]|[^2].|.[^Bb])

That is the question.
redcairo
Posts: 39
Joined: Fri May 06, 2011 6:34 am

Post by redcairo »

Is there any way to search for, say, "the last line break character in a file" or anything else that might get me to the end of content in a text file?
User avatar
kengrubb
Posts: 324
Joined: Thu Dec 11, 2003 5:23 pm
Location: Olympia, WA, USA

Post by kengrubb »

Ctrl+End for DocumentEnd

Not a search, but a valid keystroke sequence
(2[Bb]|[^2].|.[^Bb])

That is the question.
redcairo
Posts: 39
Joined: Fri May 06, 2011 6:34 am

Post by redcairo »

Yeah, I do that, but it means I have to do it individually... I have tons of files.
User avatar
MudGuard
Posts: 1295
Joined: Sun Mar 02, 2003 10:15 pm
Location: Munich, Germany
Contact:

Re: End of File symbol

Post by MudGuard »

redcairo wrote:I finally found a reference to "end of file" being slash z. ( /z )
Read the stuff you linked here again.

There is no mention of /z.

The regex part for the end of the buffer is not Slash zed (/z), it is backslash zed (\z).

Searching for e.g.

Code: Select all

...\z
selects the last three characters of the file in Textpad 7.5.1 - as expected. And as described in TP 7.5.1 Help (Help, Help Topics, Reference Information, Regular Expressions).

Support for \z seems to have been removed with Textpad 8. It does not work with TP8, and is also no longer mentioned in the Regex help page. Also no longer mentioned are \Z, \A, \' and \` ...
ben_josephs
Posts: 2456
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Yes, the start-of-file and end-of-file expressions, which worked buggily in TextPad 7, appear to have been removed in TextPad 8.

Try
(?![\s\S])
which should match anywhere that is not followed by a white-space or non-white-space character (that is, any character including a newline). That is, it should match at the end of the file. In fact, it matches at the start of the file as well (this is a bug carried over from TextPad 7), but if the cursor is anywhere other than at the end of the file it matches next at the end.
redcairo
Posts: 39
Joined: Fri May 06, 2011 6:34 am

Post by redcairo »

I don't know how I missed this before. Ben, thank you so very much for the response here. I used that to search inside a file and you're right, it led right to the end!

I attempted to search/replace with it on more than one file, figuring if it hit the start of the file too that's fine as I know what's there and a s/r could take care of that after. I killed the program, locked up. Then I realized that was stupid of me, I shouldn't be trying to replace whatever it is that I found. But I don't know how to not-replace it (I don't know what 'thing' to use to say 'that-thing here at the end of the replace').

I hope that made sense. Man I love reg ex but it's smarter than me.

If you or anybody has ideas (since my goal with this was to be able to insert something at the very end of a file -- many files at once) on how to implement that properly that would be awesome.
ben_josephs
Posts: 2456
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

You might have been recovering from Christmas...

The regex (?![\s\S]) matches an empty string that is not followed by any character, that is, it matches the empty string at the end of the file. If you replace that empty string with something, then the something is inserted at the end of the file and the cursor is now just past what has been inserted, at the (new) end of the file. So if you match again you match just where you are, at the end of the file. Repeated replacements repeatedly insert the something at the end of the file. This has been discussed here before.

You can solve this problem by matching non-empty strings. When a non-empty string at the end of the file has been replaced by something, the cursor is at the end of the file, and the regex cannot match at that position as there is no non-empty string there. Try the following. It matches and replaces a single character that is not followed by any character:
Find what: ([\s\S])(?![\s\S])
Replace with: \1*
Post Reply