[ILUG] regexp to match anything except a line that starts with something specific

Conor McDermottroe lists at mcdermottroe.com
Mon Oct 11 13:15:18 IST 2004


On Mon, 2004-10-11 at 12:53, John Tobin wrote:
> On Mon, Oct 11, 2004 at 09:46:44AM +0000, Caolan McNamara wrote:
> > I'm trying to make a regexp which will match any line except a line that
> > starts with "slot:" I've got ^([^s]|s[^l]|sl[^o]|slo[^t]|slot[^:]).*
> > which matches any line that doesn't have "slot:" in it, but lines that
> > don't start with "slot:" but nevertheless contain it are still matched
> > by the regexp. Any ideas ? It's got to be a regexp for other
> > constraints.
> 
> Perl has a very nice negative lookahead feature:
> m/^(?!slot:)/
> will match any line not starting with slot:.
> perldoc perlre has more details.

$line !~ /^slot:/;

also works.

-C



More information about the ILUG mailing list