in reply to RegEx - match pattern not followed by literal
Perhaps using a negative lookahead?
$foo =~ /$users_regex(?!,v$)/
From perldoc perlre:
"(?!pattern)"A zero-width negative look-ahead assertion. For example "/foo(?!bar)/" matches any occurrence of "foo" that isn't followed by "bar". Note however that look-ahead and look- behind are NOT the same thing. You cannot use this for look-behind.
If you are looking for a "bar" that isn't preceded by a "foo", "/(?!foo)bar/" will not do what you want. That's because the "(?!foo)" is just saying that the next thing can- not be "foo"--and it's not, it's a "bar", so "foobar" will match. You would have to do something like "/(?!foo)...bar/" for that. We say "like" because there's the case of your "bar" not having three characters before it. You could cover that this way: "/(?:(?!foo)...|^.{0,2})bar/". Sometimes it's still easier just to say:
if (/bar/ && $` !~ /foo$/)
Update: Fixed formatting, and adding a comment that the documentation does suggest, as Fletch suggests, that it's sometimes still easier to do what Melly is originally doing.
s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: RegEx - match pattern not followed by literal
by ikegami (Patriarch) on Oct 12, 2006 at 15:39 UTC | |
by Melly (Chaplain) on Oct 12, 2006 at 15:53 UTC | |
by ikegami (Patriarch) on Oct 12, 2006 at 15:57 UTC | |
by driver8 (Scribe) on Oct 13, 2006 at 07:00 UTC | |
|
Re^2: RegEx - match pattern not followed by literal
by johngg (Canon) on Oct 12, 2006 at 15:37 UTC | |
by Melly (Chaplain) on Oct 12, 2006 at 15:42 UTC | |
by johngg (Canon) on Oct 12, 2006 at 15:47 UTC |