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

6496Re: [NH] find/replace in tags

Expand Messages
  • Alec Burgess
    Oct 6, 2008
    • 0 Attachment
      Don Strack (donstrack@...) wrote (in part) (on 2008-10-06 at
      20:39):
      > Whatever I try, it either finds nothing, or selects everything between
      > the first <td> and the last </td>

      Don: In case you are still struggling after Rudolf's and Marcello's posts?

      Sounds like you might be getting bitten by regex "greedy" mode.
      Though I'm not sure how it would get from first to last unless the html
      code is all in one line. You can control whether a . (dot) can span more
      than one line by putting either (?s) -span multiple lines or (?-s)
      -span ONLY one line at the beginning of your regular expression. If
      neither is specified, (?-s) is implied. So:

      * (?s)<td>.*</td>
      o will find from the first <td> to the LAST </td> in the
      entire file (greedy mode)
      * (?s)<td>.*?</td>
      o will find from the first <td> to the NEXT </td> even if its
      on the next or following lines. (non-greedy mode)

      Your original question was:
      > How do I strip the "class" contents of any and all tags, as below:
      >
      > change this:
      >
      > <td class="[whatever]">[whatever]<
      >
      > /td>
      >
      > to this:
      >
      > <td>[whatever]</td>
      >
      ie. class can appear in other tags than just <td> and (I assume) any
      other attributes are to be left unchanged as is - CORRECT?

      I *think* this should work:
      ^!replace "\bclass=".*?" >> "" rwsai
      In English: match from a word boundary (\b) followed by literal class="
      to the very next occurrence of quote (.*?") and replace everything
      matched by nothing.

      If this doesn't work and/or you can't make it work with a tweaking you
      can guess at .... Could you take one old file and get it to the state
      before you wanted to apply this fix and manually change it to what you
      want the result to be and zip the two files together as before.html and
      after.html?

      I created a folder in our yahoo-group files:
      http://tech.groups.yahoo.com/group/ntb-html/files/HelpMePlease/ where
      you can post the zip.

      --
      Regards ... Alec (buralex@gmail & WinLiveMess - alec.m.burgess@skype)




      [Non-text portions of this message have been removed]
    • Show all 6 messages in this topic