Melly has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monkeys,
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 @.
So...
foobar:hellogonk should give me foobar:hello
foobar:gonk shouldn't match
foobar:higonk should give me foobar:hi
foobar:helloworldgonk shouldn't match (gonk is too late)
Needless to say, the '@' isn't really a problem, but 'gonk' is giving me a real headache. Any ideas?
BTW this is only part of the regex, so
isn't really much help... and would have problems with the variable length anyway afaik.if(/whatever/ and $& !~ /gonk/)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: RegEx - match !foo followed by foo
by merlyn (Sage) on Mar 16, 2006 at 12:56 UTC | |
by Melly (Chaplain) on Mar 16, 2006 at 15:24 UTC | |
by kwaping (Priest) on Mar 16, 2006 at 15:29 UTC | |
by Melly (Chaplain) on Mar 16, 2006 at 13:38 UTC | |
|
Re: RegEx - match !foo followed by foo
by Corion (Patriarch) on Mar 16, 2006 at 13:02 UTC | |
by Melly (Chaplain) on Mar 16, 2006 at 13:31 UTC | |
by Corion (Patriarch) on Mar 16, 2006 at 13:36 UTC | |
by Melly (Chaplain) on Mar 16, 2006 at 13:45 UTC | |
by Corion (Patriarch) on Mar 16, 2006 at 13:49 UTC | |
| |
|
Re: RegEx - match !foo followed by foo
by johngg (Canon) on Mar 16, 2006 at 14:14 UTC | |
|
Re: RegEx - match !foo followed by foo
by holli (Abbot) on Mar 16, 2006 at 13:09 UTC | |
by Melly (Chaplain) on Mar 16, 2006 at 13:50 UTC |