[TriLUG] regex: match lines NOT containing X

Justis Peters justis.peters at gmail.com
Wed Feb 22 11:11:01 EST 2012


On 02/22/2012 09:56 AM, Kevin Hunter wrote:
> 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'.
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.

Kind regards,
Justis



More information about the TriLUG mailing list