ZTree.com  | ZEN  | About...  

 Index   Back

[Help!] Search for text and replace with <del> key   [Help!]

By: Art Kocsis     So Calif  
Date: May 24,2019 at 10:28
In Response to: [Help!] Search for text and replace with key (Neil Clough)

> Hi All
> I have searched the net with no luck (as usual) so I am hoping someone
> here may be able to help.
> I have a text file generated by a program.
> It has a limit to the number of characters in a line.
> If this limit is exceeded, the program splits the line and inserts a
> "$" at the end of the first line.
> I want to rejoin the lines.
> So - Search and replace.
> Find "$"
> Replace with 2 key strokes
> to rejoin the lines.

I can't believe this. This is such a trivial and commonplace task. I haven't used PSPad, Notepad++ or Textpad in years but a simple task to join lines such as this should be a simple operation in any one of them without requiring RegEx.

I now use the Notetab editor as it includes a UI and an extremely powerful script language. It is to text editors what ZTree is to file managers. The shareware version is not too expensive but the freeware version would do this just fine - either using RegEx or a simple text S&R. (Notetab implements the PCRE (Perl Compatible Regular Expressions) syntax.)

There are three different line terminators in common use for ANSI text files:
Single line feed (LF): Linux, Unix
Single carriage return (CR): Macintosh, Apple [Not so common now]
CRLF pair: DOS, Windows
Upon document loading, Notetab converts all line terminator to windows format and converts them back to the original format when closed.

To facilitate plain text editing, Notetab uses tokens for referring to control characters such as ^T (tab,x09), ^L (line feed,x0A), ^C (carriage return,x0D), ^P (new line=CRLF,x0D0A). The RegEx escape sequences \t, \n and \r represent the respective control character. The aforementioned escape sequences are standard RegEX syntax across all dialects. The \R escape sequence is a Perl and PCRE (and probably more), syntax that matches any Unicode newline sequence (which includes \r, \l, \r\n as well as a few more). The dollar sign ($), is a RegEx meta character that signals the end-of-line position but does not actually match (capture) the EOL character(s) themselves.

So with this understanding it is easy to see why none of the proffered RegEx patterns worked: "/$/?n", "\$\n", "\${1}$" [The "/" is obviously a typo.]

Unless your source is a Linux document (highly unlikely), the character following your "$" is a CR (/r), not a LF (/n). The "$" as an EOL indicator in a RegEx pattern performs a look-ahead function. It will never replace match the actual EOL sequence in order for it to be deleted.

So, a RegEx pattern that would join your lines is: Replace "\$\R" with null
Or, in Notetab parlance: Replace $^P with null

If you need to do this frequently, save the following as a "clip" and drag it to the "clipbar". Then just click on the icon to process an entire open document:

^!Replace "$^P" >> "" AIW

Notetab may be downloaded from: https://www.notetab.com/
There is an active forum on Yahoo for help with Notetab, RegEx, clips, et al [or PM me].

HTH, Art

Namaste', Art

Press any key to exit,
Press any other key to continue...
- unknown

Thread locked

Messages in this Thread

94,967 Postings in 11,969 Threads, 349 registered users, 28 users online (2 registered, 26 guests)
Index | Admin contact |   Forum Time: May 25, 2020 - 8:04 pm EDT  |  Hits:31,230,052  (6,399 Today )
RSS Feed