2 Replies Latest reply: Jan 7, 2014 7:50 AM by John L. RSS

    regular expression question

    John L.


      I currently use the regular expression (\b.*[>]Temp:?) to select the following 2 lines:

       

      <div align="center" class="smTxt">Temp: <span class="smTxt" style="font-weight: bold;">37.8&deg;F</span>

      <div class="smTxt">Temp: 37.8&deg;F</div>

       

      How can I modify my regular expression to exclude the first of the two selected lines, but not the second?

       

      Thanks in advance for any help you may be able to provide.

        • 1. Re: regular expression question
          TPD-Opitz

          Your requirement is not clear to me. The semantic content of both lines is the same  (Temp: 37.8&deg;F), the rest is just HTML fomatting. Why can you skip the first line but not the second? Schouldn't you look for a way to ignore the <span>-Tag only instead of the whole line? Also I'd recommend a framework for parsing HTML because there may be line breaks that split your line and you may not find it.

           

          Having sad this a look ahead expression may do it:

          (\b.*[>]Temp:?)\s*(?![<])

          or

          (\b.*[>]Temp:?)\s*(?=\d)

           

          bye

          TPD

          • 2. Re: regular expression question
            John L.

            Thanks for your kid answer. My experience to date with one HTML parsing framework is that it does not live up to the proposed design.

             

            In the meantime, I'll suffice with regular expressions with the aid of my peers.