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

Re: [Clip] Regex Replace

Expand Messages
  • Axel Berger
    ... I have a clip for just that frequently occurring task. It does a few things more like hyphenation and corrects some frequent errors in scanned or copied
    Message 1 of 6 , May 11, 2010
    • 0 Attachment
      C wrote:
      > This is because a software create a text (.txt) but with
      > irregular line lenghts, and I want to replace all the
      > lines, and later, wordwrap off.

      I have a clip for just that frequently occurring task. It does a few
      things more like hyphenation and corrects some frequent errors in
      scanned or copied text blocks:

      ^!Replace "^ *(.*?)$" >> $1 WRASI
      ^!Replace ",," >> """ WASI
      ^!Replace "([,.!?;:])(\w)" >> "$1 $2" WRASI
      ^!Replace "-^P" >> "" WASI
      ^!Replace "^P^P" >> "^T^T" WASI
      ^!Replace "^P" >> " " WASI
      ^!Replace "\f" >> "\n" WRASI
      ^!Replace "^T^T" >> "^P^P" WASI
      ^!Replace " +^P^P" >> "^P^P" WRASTI

      The line
      ^!Replace "\f" >> "\n" WRASI
      is special. There are times when a sequence of short lines ought to be
      preserved. In that case I mark those as a block and run this

      ^!Replace "^P" >> "^%PAGE%" HASI

      on them before doing the whole text with the first clip.

      Axel
    • C
      Thanks, great Axel. Worked fine.
      Message 2 of 6 , May 11, 2010
      • 0 Attachment
        Thanks, great Axel. Worked fine.


        --- In ntb-clips@yahoogroups.com, Axel Berger <Axel-Berger@...> wrote:
        >
        > C wrote:
        > > This is because a software create a text (.txt) but with
        > > irregular line lenghts, and I want to replace all the
        > > lines, and later, wordwrap off.
        >
        > I have a clip for just that frequently occurring task. It does a few
        > things more like hyphenation and corrects some frequent errors in
        > scanned or copied text blocks:
        >
        > ^!Replace "^ *(.*?)$" >> $1 WRASI
        > ^!Replace ",," >> """ WASI
        > ^!Replace "([,.!?;:])(\w)" >> "$1 $2" WRASI
        > ^!Replace "-^P" >> "" WASI
        > ^!Replace "^P^P" >> "^T^T" WASI
        > ^!Replace "^P" >> " " WASI
        > ^!Replace "\f" >> "\n" WRASI
        > ^!Replace "^T^T" >> "^P^P" WASI
        > ^!Replace " +^P^P" >> "^P^P" WRASTI
        >
        > The line
        > ^!Replace "\f" >> "\n" WRASI
        > is special. There are times when a sequence of short lines ought to be
        > preserved. In that case I mark those as a block and run this
        >
        > ^!Replace "^P" >> "^%PAGE%" HASI
        >
        > on them before doing the whole text with the first clip.
        >
        > Axel
        >
      • diodeom
        ... There is a dedicated menu item to join lines of (selected) text while preserving any blank ones: Modify/Lines/Join Lines (or Ctrl+J). To process the entire
        Message 3 of 6 , May 11, 2010
        • 0 Attachment
          "C" <backup2abet@...> wrote:
          >
          > I need to replace
          >
          > ^Px ---> " x"
          >
          > In other words , each new line (^P) followed by any character (x), but not new lines followed by ^p or nothing.
          >

          There is a dedicated menu item to join lines of (selected) text while preserving any blank ones: Modify/Lines/Join Lines (or Ctrl+J). To process the entire document you could use:

          ^!Select All
          ^!Menu Modify/Lines/Join Lines

          or exactly as you suggested:

          ^!Replace ".\K\R(?!\R)" >> " " WARS

          . any single character
          \K don't include the preceeding match
          \R your *target* newline sequence
          (?!\R) lookahead assertion "NOT followed by another newline"
          W start at the beginning of the (Whole) doc
          A replace All instances
          R use Regex
          S Silently (Surpress message boxes)
        • Don
          ... I want to thank you for taking the time to explain this diodeom. I learn so much from these explained examples. I am getting better all the time, but
          Message 4 of 6 , May 11, 2010
          • 0 Attachment
            > ^!Replace ".\K\R(?!\R)">> " " WARS
            >
            > . any single character
            > \K don't include the preceeding match
            > \R your *target* newline sequence
            > (?!\R) lookahead assertion "NOT followed by another newline"
            > W start at the beginning of the (Whole) doc
            > A replace All instances
            > R use Regex
            > S Silently (Surpress message boxes)

            I want to thank you for taking the time to explain this diodeom. I
            learn so much from these explained examples. I am getting better all
            the time, but look aheads and what not still confuse me :-)

            So this (?!\R) could be read as AND NOT return character next essentially.
          • John Shotsky
            This will do as you wish, without regard for any punctuation, parentheses or hyphenation: If those matter, a character class can be used with the /w:
            Message 5 of 6 , May 11, 2010
            • 0 Attachment
              This will do as you wish, without regard for any punctuation, parentheses or hyphenation: If those
              matter, a character class can be used with the /w: [\w\(\)\"\(, \.] (Add any other characters you
              may encounter on ends of lines)
              ^!Replace "(\w)\R(\w)" >> "$1\x20$2" ARSTW

              This:
              jhjh jhjh jhjh jhjh
              gg hgh hgh ghg
              mnmn mnmn mnmn mnmn

              jhjh jhjh jhjh jhjh
              gg hgh hgh ghg
              mnmn mnmn mnmn mnmn

              Becomes this:
              jhjh jhjh jhjh jhjh gg hgh hgh ghg mnmn mnmn mnmn mnmn

              jhjh jhjh jhjh jhjh gg hgh hgh ghg mnmn mnmn mnmn mnmn

              Regards,
              John

              From: ntb-clips@yahoogroups.com [mailto:ntb-clips@yahoogroups.com] On Behalf Of C
              Sent: 11 May, 2010 04:33 AM
              To: ntb-clips@yahoogroups.com
              Subject: [Clip] Regex Replace


              Hi friends,

              I need to replace

              ^Px ---> " x"

              In other words , each new line (^P) followed by any character (x), but not new lines followed by ^p
              or nothing.

              This is because a software create a text (.txt) but with irregular line lenghts, and I want to
              replace all the lines, and later, wordwrap off.

              In other words, the original text is

              jhjh jhjh jhjh jhjh(nl)
              gg hgh hgh ghg(nl)
              mnmn mnmn mnmn mnmn(nl)
              (no characters at this line)

              and must be changed to

              jhjh jhjh jhjh jhjh gg hgh hgh ghg mnmn mnmn mnmn mnmn(nl)

              Naturally, this is a job for a Regex replace, please kindly help

              Brito



              [Non-text portions of this message have been removed]
            Your message has been successfully submitted and would be delivered to recipients shortly.