in reply to RegEx - match !foo followed by foo

Not sure I completely understand, but does this do it for you?
if (/^(foobar:((?!=gonk|\@).)+)/) { print "matched $1\n"; }
That's your classic "inchworm" pattern, so it's not the fastest in the world.

-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply.


update: Yeah, just like in real life, he changes the spec after I write the implementation. {grin}

And the spec is still broken:

I'm having problems working out how to perform the following regex. I want to match foobar:Xgonk where X is between 1 and 5 characters, and can be anything except 'gonk' (or the beginning of 'gonk') or '@'. I then want to remove gonk or @.
The last "or @" is spurious. There could never be an "@" there, since it has to have a trailing "gonk" where we stop.

Replies are listed 'Best First'.
Re^2: RegEx - match !foo followed by foo
by Melly (Chaplain) on Mar 16, 2006 at 15:24 UTC

    LOL - you think you've got it bad, this wasn't even my specification, and the guy doing that actual spec. had absolutely no idea what he was asking for (or at least was incapable of expressing it).

    It was like asking a 2-year old for the plot of "The Tale of Peter Rabbit" - they just say "rabbits" over and over again...

    Yeah, in my spec. the "or @" is spurious (and the whole @ is something of a red herring). In RealLife(tm) 'gonk' can either be 'gonk' or @ at all stages (the actual strings are '|' or '\.br\')

    Anyway, Corion's final solution got me there... I'd get him to give you a few perl-lessons, he obviously knows way more than you ;)

    Tom Melly, tom@tomandlu.co.uk
      Extra ++ for a good sense of humor. :)

      ---
      It's all fine and dandy until someone has to look at the code.
Re^2: RegEx - match !foo followed by foo
by Melly (Chaplain) on Mar 16, 2006 at 13:38 UTC

    Hi Merlyn

    Sorry, my explanation was ambiguous (and had a mistake) - please see my reply to Corion

    Many thanks (we are not worthy)

    Tom Melly, tom@tomandlu.co.uk