Regular expression to match a line that doesn’t contain a word ?

Regular expression to match a line that doesn’t contain a word ?

Asked on December 14, 2018 in Regex.
Add Comment


  • 2 Answer(s)

    Sample code:

    Note that the solution to does not start with “hede”:

    ^(?!hede).*$
    

    Generally much more efficient than the solution to does not contain “hede”:

    ^((?!hede).)*$
    

    The former checks for “hede” only at the input string’s first position, rather than at every position.

    Answered on December 14, 2018.
    Add Comment

    Try this:

    wherever you just using it for grep, you can use grep -v hede to get all lines which do not contain hede.

    ETA Oh, rereading the question, grep -v is probably  by “tools options”.

    Answered on December 14, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.