End of File symbol
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
End of File symbol
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.
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.
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
http://superuser.com/questions/427514/w ... nd-of-file
Re: End of File symbol
Read the stuff you linked here again.redcairo wrote:I finally found a reference to "end of file" being slash z. ( /z )
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
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 \` ...
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
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.
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.
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.
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.
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
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:
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*