in reply to Re: Re: Help with Regular Expression matching
in thread Help with Regular Expression matching

How about or-ing the regexp then?

my ($match) = $string =~ /<(ab)>|(ab)/;
Steve
---
steve.org.uk

Replies are listed 'Best First'.
Re: Re: Help with Regular Expression matching
by Anonymous Monk on Feb 18, 2004 at 10:41 UTC
    This will capture <ab> into $1 and ab into $2 - This means that $match will not capture ab.
Re: Re: Help with Regular Expression matching
by davis (Vicar) on Feb 18, 2004 at 10:43 UTC

    As our friend notes, you mean:

    my ($match) = $string =~ /(<ab>|ab)/;
    Update: Ok, I didn't read the spec carefully enough, I think this will do it:
    my ($match) = $string =~ /(?!<ab[^>]|[^<]ab>)<?(ab)>?/
    But I'd probably split it into two regexes.

    I'm talking twaddle, anyone else want a go?


    davis
    It's not easy to juggle a pregnant wife and a troubled child, but somehow I managed to fit in eight hours of TV a day.
      This is close, but I don't want to capture the surrounding brackets.