in reply to RegEx - match !foo followed by foo
I read your problem differently than merlyn does. It seems to me that you want to match only if there is gonk at the end of the string, and you only care for up to the first five letters of the word between foobar: and gonk:
use strict; use Test::More tests => 4; sub ungonk { local $_ = $_[0]; if (/^(foobar:.{1,5}).*gonk$/) { return $1 } else { return undef }; }; is ungonk('foobar:hellogonk'), 'foobar:hello'; is ungonk('foobar:gonk'), undef; is ungonk('foobar:higonk'), 'foobar:hi'; is ungonk('foobar:helloworldgonk'), 'foobar:hello';
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: RegEx - match !foo followed by foo
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 | |
by Melly (Chaplain) on Mar 16, 2006 at 13:57 UTC |