[TriLUG] regex: match lines NOT containing X
William Sutton
william at trilug.org
Wed Feb 22 10:19:30 EST 2012
erm, my bad. If you're doing this Perl-wise, or anything else that has
the !~ operator as well as =~,
my @a = (
"If two heads are better than one,",
"are two keyboards better than one?",
"Would you say the same if it were two hydra heads?"
);
foreach my $a (@a)
{
print $a, "\n" if $a !~ m/heads/i;
}
William Sutton
On Wed, 22 Feb 2012, William Sutton wrote:
> Have you tried /[^(head)]/i ?
>
> William Sutton
>
> On Wed, 22 Feb 2012, Kevin Hunter wrote:
>
>> Hullo List,
>>
>> An actual technical question here: Is there a way to match an entire line
>> such that the entire line does *not* contain a sequence of characters?
>>
>> Example input containing three lines:
>> -----
>> If two heads are better than one,
>> are two keyboards better than one?
>> Would you say the same if it were two hydra heads?
>> -----
>>
>> My criteria is very specific: I want lines that do *not* contain 'heads'.
>> My first thought was to use an assertion:
>>
>> /^.*two.*(?!heads).*$/
>>
>> However, this naive implementation matches both lines 2 and 3. I've needed
>> this construct more than a few times, so I'm almost sure it exists; I just
>> don't know the right Google terms, apparently. On the other hand, I could
>> accept that this may not be possible in a single step regex.
>>
>> Any ideas?
>>
>> Thanks,
>>
>> Kevin
>> --
>> This message was sent to: William <william at trilug.org>
>> To unsubscribe, send a blank message to trilug-leave at trilug.org from that
>> address.
>> TriLUG mailing list : http://www.trilug.org/mailman/listinfo/trilug
>> Unsubscribe or edit options on the web :
>> http://www.trilug.org/mailman/options/trilug/william%40trilug.org
>> TriLUG FAQ : http://www.trilug.org/wiki/Frequently_Asked_Questions
>>
> --
> This message was sent to: William <william at trilug.org>
> To unsubscribe, send a blank message to trilug-leave at trilug.org from that
> address.
> TriLUG mailing list : http://www.trilug.org/mailman/listinfo/trilug
> Unsubscribe or edit options on the web :
> http://www.trilug.org/mailman/options/trilug/william%40trilug.org
> TriLUG FAQ : http://www.trilug.org/wiki/Frequently_Asked_Questions
>
More information about the TriLUG
mailing list