in reply to regex problem
# $re = exclude(@words); sub exclude { my %words; push @{ $words{ quotemeta substr($_, 0, 1) } }, quotemeta substr($_, 1) for @_; my $first = "[^@{[ join '', keys %words ]}]*"; my $rest = join "|", map "$_(?!" . join("|", @{ $words{$_} }) . ")", keys %words; return qr/^$first(?:(?:$rest)$first)*$/; } my $re = exclude(qw( this that those )); # print $re; # for debugging purposes for ("I like this", "give me that one", "these rock!") { print "$_ => " . /$re/; }
_____________________________________________________
Jeff[japhy]Pinyan:
Perl,
regex,
and perl
hacker.
s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Word Exclusion Regex (was Re: regex problem)
by blakem (Monsignor) on Feb 10, 2002 at 10:27 UTC | |
by japhy (Canon) on Feb 10, 2002 at 16:19 UTC | |
by blakem (Monsignor) on Feb 10, 2002 at 17:41 UTC | |
by japhy (Canon) on Feb 10, 2002 at 17:57 UTC | |
by japhy (Canon) on Feb 10, 2002 at 17:48 UTC | |
by chipmunk (Parson) on Feb 10, 2002 at 17:49 UTC | |
|
Re: Word Exclusion Regex (was Re: regex problem)
by Juerd (Abbot) on Feb 09, 2002 at 21:57 UTC |