olivierp has asked for the wisdom of the Perl Monks concerning the following question:
I have a file containing records separated by a |.
In order to classify these entries, I first split each line, and match certain fields against a hash of filters.
The filters are loaded from a configuration file at run-time.
I am thus limited to $var[5] =~ /$regex/ (or at least I think so) for my matching.
Is it possible to get something like this to work:
$re[0] = qr (.*(?!system))i; $re[1] = qr (system)i; $v[0] = "oneitem"; $v[1] = "anothersystem"; for $a (@v) { for $r (@re) { print "\nRegex: $r\tValue: $a\n"; if ($a =~ /$r/) { print "$a matches $r\n" ; } } }
As this results in:
Regex: (?-xism:.*(?!system)) Value: oneitem oneitem matches (?-xism:.*(?!system)) Regex: (?-xism:system) Value: oneitem Regex: (?-xism:.*(?!system)) Value: anothersystem anothersystem matches (?-xism:.*(?!system)) Regex: (?-xism:system) Value: anothersystem anothersystem matches (?-xism:system)
Which is not what I want...
Is it possible to construct a regex that "matches if doesn't contain" ?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Backtracking problem with .*(?!bar)
by BrowserUk (Patriarch) on Sep 24, 2003 at 09:19 UTC | |
by olivierp (Hermit) on Sep 24, 2003 at 10:14 UTC | |
by merlyn (Sage) on Sep 24, 2003 at 10:27 UTC | |
by olivierp (Hermit) on Sep 24, 2003 at 10:37 UTC | |
|
Re: Backtracking problem with .*(?!bar)
by Abigail-II (Bishop) on Sep 24, 2003 at 09:10 UTC | |
|
Re: Backtracking problem with .*(?!bar)
by vbrtrmn (Pilgrim) on Sep 24, 2003 at 13:34 UTC | |
by merlyn (Sage) on Sep 24, 2003 at 20:04 UTC | |
by tsee (Curate) on Sep 25, 2003 at 10:15 UTC | |
by perlguy (Deacon) on Sep 24, 2003 at 14:21 UTC |