[TriLUG] regex: match lines NOT containing X

Kevin Hunter hunteke at earlham.edu
Wed Feb 22 11:19:18 EST 2012


At 11:11am -0500 Wed, 22 Feb 2012, Justis Peters wrote:
> On 02/22/2012 09:56 AM, Kevin Hunter wrote:
>> -----
>> 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'.
>
> If the regex library you are using has "negative lookahead", you can do
> this:
> /^((?!heads).)*$/;
>
> Thanks to http://stackoverflow.com/a/406408/795280 for this answer.

Oh oh!  I /knew/ someone would have solved this before.  Alas.  Your 
Google is better than my Google.  Thank you!  And you beat me to the 
list.  You get the glory.  :-)

Thanks for the pointer.  Much better explained that I just did, obviously.

Cheers,

Kevin



More information about the TriLUG mailing list