how to get around greedy * operator?

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

    how to get around greedy * operator?

    What regular expression would return only...
    id="Table3"

    from the string...
    height="100%" id="Table3" cellspacing="0" cellpadding="0" width="100%"

    I tried...
    id=".*"

    but I get a match to the end of the line.

    I also tried...
    id=".*?"

    but that didn't find anything.

    Thanks for the help,
    John
  • Lasse Reichstein Nielsen

    #2
    Re: how to get around greedy * operator?

    John Livermore <john.livermore @nospm-inginix.com> writes:
    [color=blue]
    > What regular expression would return only...
    > id="Table3"
    >
    > from the string...
    > height="100%" id="Table3" cellspacing="0" cellpadding="0" width="100%"[/color]

    The simplest (generalizable) regular expression would be
    /id="[^"]*"/

    [color=blue]
    > I also tried...
    > id=".*?"
    >
    > but that didn't find anything.[/color]

    Suprising, depending on what browser you tested in. It should work
    in a browser understanding ECMAScript v3 Regular Expressions.
    It works for me in Opera 7 and IE 6.

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    Working...