regex help

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sunny

    regex help

    Hi,
    I know that this is not the very right group, but I can not find better,
    and I have seen a lot of regex experts to answer, so I'll give a shot:

    Lets have this string:
    "<table name='xxx'><br> \nMY_TEXT\n<\ta ble><p>"

    please note the new line characters.

    So, using a regex like:
    "</?table.*>"

    will find these:

    "<table name='xxx'><br> " and
    "<\table><p >"

    How should like a regex to get only the table tags? I want to leave <br>
    and <p> unmatched? How to stop the match to the first occurrence of ">",
    not the last one?

    I.e. if I replace the match with an empty string, I want to receive:
    "<br>\nMY_TEXT\ n<p>",

    but not what I have now:
    "\nMY_TEXT\ n"


    Cheers
    Sunny
  • Sunny

    #2
    Re: regex help

    I found it:

    "</?table.*?>"

    The second ? makes lazy *, i.e. as few repeats as possible.

    Thanks for reading, and hope this can help someone.

    SUnny


    In article <umHd2MYoEHA.38 96@TK2MSFTNGP15 .phx.gbl>,
    sunny@newsgroup s.nospam says...[color=blue]
    > Hi,
    > I know that this is not the very right group, but I can not find better,
    > and I have seen a lot of regex experts to answer, so I'll give a shot:
    >
    > Lets have this string:
    > "<table name='xxx'><br> \nMY_TEXT\n<\ta ble><p>"
    >
    > please note the new line characters.
    >
    > So, using a regex like:
    > "</?table.*>"
    >
    > will find these:
    >
    > "<table name='xxx'><br> " and
    > "<\table><p >"
    >
    > How should like a regex to get only the table tags? I want to leave <br>
    > and <p> unmatched? How to stop the match to the first occurrence of ">",
    > not the last one?
    >
    > I.e. if I replace the match with an empty string, I want to receive:
    > "<br>\nMY_TEXT\ n<p>",
    >
    > but not what I have now:
    > "\nMY_TEXT\ n"
    >
    >
    > Cheers
    > Sunny
    >[/color]

    Comment

    Working...