regexjeditand-operator

regex AND operator with negative arguments


I'm trying to match lines that doesn't end with either . or ! and doesn't end with either ." or !" so it should match both

but shouldn't match:

I tried using positive and negative lookahead, trying to use them as AND as suggested in Regex AND operator, but I can't make it work, nor I'm sure it's feasible with lookaheads.


Solution

  • Just use a negative lookbehind. This matches exactly what you asked for: ^.*+(?<![.!]"?)$


    ^ - beginning of line
    .*+ - any amount of characters, not giving up for backtracking
    (?<! + ) - not preceded by
    [.!] - dot or exclamation mark
    "? - optional double-quote
    $ - end of line