-2

In my case I want to find (using python regex) all lines not containing the words "error" or "empty". In code:

varformals : PAR_OPEN PAR_CLOSE {}
| PAR_OPEN varform PAR_CLOSE {}
/* error / | error PAR_CLOSE {}
/
error / | error varform PAR_CLOSE {}
/
error */ | PAR_OPEN error PAR_CLOSE {}
;

Flexo
  • 87,323
  • 22
  • 191
  • 272
HackSlash
  • 11
  • 2

1 Answers1

1

Regex101

(^((?!error|empty).)*$)

Regular expression visualization

Debuggex Demo

description

1st Capturing group (^((?!error|empty).)*$)
    ^ assert position at start of a line
2nd Capturing group ((?!error|empty).)*
    Quantifier: * Between zero and unlimited times, as many times as possible, giving back as needed [greedy]
    Note: A repeated capturing group will only capture the last iteration.
    Put a capturing group around the repeated group to capture all 
    iterations or use a non-capturing group instead if you're not interested 
    in the data
    (?!error|empty) Negative Lookahead - Assert that it is impossible to match the regex below
        1st Alternative: error
            error matches the characters error literally (case sensitive)
        2nd Alternative: empty
            empty matches the characters empty literally (case sensitive)
    . matches any character (except newline)
$ assert position at end of a line
g modifier: global. All matches (don't return on first match)
m modifier: multi-line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)
abc123
  • 17,855
  • 7
  • 52
  • 82