Using a Perl or unix regex, how would I capture a word that is not a range of values. Here is what I am trying to achieve.
(\w:not('int','long'))
Using a Perl or unix regex, how would I capture a word that is not a range of values. Here is what I am trying to achieve.
(\w:not('int','long'))
Not sure if this is valid perl syntax, but in "generic" flavor you can say
/\b(?!int\b|long\b)\w+\b/
If you want to capture the word, put parens around \w+
, like this
/\b(?!int\b|long\b)(\w+)\b/
It is generally faster to say:
my %exclude = map { $_ => 1 } qw/int long/;
my @words = grep { not exists $exclude{$_} } /(?:\b|^) (\w+) (?:\b|$)/gx;
especially on versions of Perl prior to 5.10 (when alternation got a massive speed increase).