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

18986Re: Using regex to insert a comment

Expand Messages
  • Flo
    Mar 3, 2009
    • 0 Attachment
      --- In ntb-clips@yahoogroups.com, "paulmaser" <paul@...> wrote:
      >
      > Flo;
      > Here is what today's post look like at the moment...

      Paul,

      That's a lot of lines -- could we reduce it as follows?


      <!-- Asia-Pacific: -->
      <!-- Asia: -->
      <!-- East Asia: -->
      <li><b><i>AP Google</i></b> - <a href=...Eric Talmadge
      <li><b><i>AFP Google</i></b> - <a href=...talks</a>
      <li><b><i>Reuters UK</i></b> - <a href=...talks</a>
      <!-- Southeast Asia: -->
      <!-- Europe: -->
      <li><b><i>Derby Evening Telegraph</i></b> - <a href=...reactor</a>
      <!-- North Europe: -->


      Different from your first example, the number of those "added lines" now differs from comment to comment. I assume that the "added lines" contain *no CRNL* (i.e., they are multiple lines of a single paragraph only).

      When running the following clip on these lines...


      ^!SetScreenUpdate Off
      ^!SetWordWrap Off
      ^!Jump Doc_Start
      :Start
      ^!Find "(?s)^<!--[^-]+-->\x20\r\n<li>.+?((?=^<!)|\Z)" RS
      ^!IfError End
      ; Long line start
      ^!SetClipboard ^$GetDocMatchAll("^<\!--\x20\K([^-]+)(?=-->\x20\r\n<li>)")$
      ; Long line end
      ^!Replace "(<li>)(<b>)" >> "$1^$GetClipboard$$2" HARS
      ^!Jump Select_End
      ^!If ^$GetRow$=^$GetTextLineCount$ End
      ^!Goto Start


      ...the result is:


      <!-- Asia-Pacific: -->
      <!-- Asia: -->
      <!-- East Asia: -->
      <li>East Asia: <b><i>AP Google</i></b> - <a href=...Eric Talmadge
      <li>East Asia: <b><i>AFP Google</i></b> - <a href=...talks</a>
      <li>East Asia: <b><i>Reuters UK</i></b> - <a href=...talks</a>
      <!-- Southeast Asia: -->
      <!-- Europe: -->
      <li>Europe: <b><i>Derby Evening Telegraph</i></b> - <a href=...reactor</a>
      <!-- North Europe: -->


      I hope this will match your intentions...

      Regards,
      Flo

      P.S. I also played around with the following solution -- with a long list, it will be slower...


      ^!SetWordWrap Off
      ^!Jump Doc_Start
      :Start
      ^!Find "^<\!--\x20\K([^-]+)(?=-->\x20\r\n<li>)" RS
      ^!IfError End
      ^!Set %Body%=^$GetSelection$
      ^!Jump +1
      ^!IfSame "<li>" "^$StrCopyLeft("^$GetLine$";4)$" Next Else Start
      ^!Replace "(<li>)(<b>)" >> "$1^%Body%$2" RS
      ^!If ^$GetRow$=^$GetTextLineCount$ End
      ^!Goto Skip_-4
    • Show all 15 messages in this topic