Regular expression help needed

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • b007uk@gmail.com

    #1

    Regular expression help needed

    Hi everyone,
    Could someone please help me with this regular expression,
    this is the string:

    <top cellpadding=2 ><tr><td valign=top><b>D VD</bduel:
    <b>High</b>-<b>definition </bshowdown<br><f ont size=-1><font
    color=6f6f6f>TM Cn vxcv etrwerwerwer <brsdfsd <bdfasdasd <br>
    asdasda

    I need to match everything from <td valign=topto the first <br>, like
    this:
    <td valign=top><b>D VD</bduel: <b>High</b>-<b>definition </b>
    showdown<br>

    These are the expressions i tried:

    <td valign=top>.*<b r>
    <td valign=top>.*<b r>{0,1}
    <td valign=top>.*<b r>{1,1}

    They all match everything untill the LAST break, and i only need first
    occurrence of break <br>
    :(
    Thank you very much!

  • Rik

    #2
    Re: Regular expression help needed

    b007uk@gmail.co m wrote:
    Hi everyone,
    Could someone please help me with this regular expression,
    this is the string:
    >
    <top cellpadding=2 ><tr><td valign=top><b>D VD</bduel:
    <b>High</b>-<b>definition </bshowdown<br><f ont size=-1><font
    color=6f6f6f>TM Cn vxcv etrwerwerwer <brsdfsd <bdfasdasd <br>
    asdasda
    >
    I need to match everything from <td valign=topto the first <br>,
    like this:
    <td valign=top><b>D VD</bduel: <b>High</b>-<b>definition </b>
    showdown<br>
    >
    These are the expressions i tried:
    >
    <td valign=top>.*<b r>
    <td valign=top>.*<b r>{0,1}
    <td valign=top>.*<b r>{1,1}
    >
    They all match everything untill the LAST break, and i only need first
    occurrence of break <br>
    :(
    Searching in this group would have revealed the answer, others and I have
    said it numerous times the last 2 weeks:

    Make your * ungreedy by placing a questionmark beside it:
    <td valign=top>.*?< br>

    I would have made it:
    '|<td[^>]*valign=top[^>]*>(.*?)<br|si'

    Advantages:
    1. Now the "valign=top " is cheched, but the td tag may get other attributes
    in the future, which will now be no problem.
    2. I've left the last of <brout, to comply with the possibilities of
    <br>, <br/& <br />.
    3. Parenthasis around the actual content you like to to get/match, so it can
    be referred to later without extra code.

    Grtz,
    --
    Rik Wasmus


    Comment

    • b007uk@gmail.com

      #3
      Re: Regular expression help needed

      Rik wrote:
      b007uk@gmail.co m wrote:
      Hi everyone,
      Could someone please help me with this regular expression,
      this is the string:

      <top cellpadding=2 ><tr><td valign=top><b>D VD</bduel:
      <b>High</b>-<b>definition </bshowdown<br><f ont size=-1><font
      color=6f6f6f>TM Cn vxcv etrwerwerwer <brsdfsd <bdfasdasd <br>
      asdasda

      I need to match everything from <td valign=topto the first <br>,
      like this:
      <td valign=top><b>D VD</bduel: <b>High</b>-<b>definition </b>
      showdown<br>

      These are the expressions i tried:

      <td valign=top>.*<b r>
      <td valign=top>.*<b r>{0,1}
      <td valign=top>.*<b r>{1,1}

      They all match everything untill the LAST break, and i only need first
      occurrence of break <br>
      :(
      >
      Searching in this group would have revealed the answer, others and I have
      said it numerous times the last 2 weeks:
      >
      Make your * ungreedy by placing a questionmark beside it:
      <td valign=top>.*?< br>
      >
      I would have made it:
      '|<td[^>]*valign=top[^>]*>(.*?)<br|si'
      >
      Advantages:
      1. Now the "valign=top " is cheched, but the td tag may get other attributes
      in the future, which will now be no problem.
      2. I've left the last of <brout, to comply with the possibilities of
      <br>, <br/& <br />.
      3. Parenthasis around the actual content you like to to get/match, so it can
      be referred to later without extra code.
      >
      Grtz,
      --
      Rik Wasmus
      Thank you so much!
      it works like a charm!

      Comment

      Working...