Loading ...
Sorry, an error occurred while loading the content.

423Re: [NTS] Changing CR & LF

Expand Messages
  • Art Kocsis
    Jun 12, 2008
      Even though it's kind of embarrassing to display a kludgy clip, I thought I
      would share this in the hopes that it would inspire other RegEx beginners
      to learn and use RegEx.

      Years ago I got tired of all the empty lines in HTML pages that I was editing
      (largely due to WYSIWYG editors such as FrontPage), I decided to write a
      clip to get rid of them. I don't know if this was my first clip or not but
      it was
      early. One of my big problems was handling the various line terminators -
      CR, LF, CRLF - that appeared in the code. I did not learn until last month
      that they were all converted to CRLF in the working image. Even so, the ^P
      token did not work consistently so I came up with this scheme. It worked
      but was quite slow. Finally losing patience with its slowness, I decided to
      redo the clip using RegEx. As you know, with your help, I was successful.
      Below, for your amusement/education/motivation are the before & after clips.

      Three lessons can be learned:

      1) Even kludges can be made to work and are useful. Keep trying.
      2) RegEx is quite esoteric yet is conquerable and is extremely efficient.
      3) We need better documentation, especially a User Guide.

      Enjoy, Art

      Note: NoteTab has EXTREMELY picky syntax. When it says "space delimited"
      that means a SINGLE space - two or more spaces => "syntax error"!

      ;^!Replace "SearchText" >> "ReplaceText" [Options TCIBGWHRSA]
      ; W: Whole. Search entire document (not just from the cursor position).
      ; S: Silent. NoteTab will not display any message box.
      ; A: All. Replace matched occurrences, not just first one.
      ; "ALT+M" invokes the Modify menu
      ; "L" invokes the Lines submenu
      ; "T" trims the selected text

      ;######### Old, Non-RegEx Clip. Could take 30 sec or more on a 40K file
      ^!StatusShow Running Single Space
      ^!Toolbar Select All
      ^!Keyboard ALT+M L T
      ^!Replace "^L" >> "^C" WSA
      ^!Replace "^C^C^C^C^C^C" >> "^C" WSA
      ^!Replace "^C^C^C^C^C" >> "^C" WSA
      ^!Replace "^C^C^C^C" >> "^C" WSA
      ^!Replace "^C^C^C" >> "^C" WSA
      ^!Replace "^C^C" >> "^C" WSA
      ^!Replace "^C" >> "^P" WSA
      ^!Jump Doc_Start

      ;######### New, RegEx Clip. Takes a fraction of a second on even very large
      ^!StatusShow Running Single Space
      ^!Toolbar Select All
      ^!Keyboard ALT+M L T
      ^!Replace "\R+" >> "^%NL%" ARSTW
      ^!Jump Doc_Start
    • Show all 16 messages in this topic