I've searched through all of the TextPad regex postings on superuser.com and have not found an answer to my query. It is -- how can I provide two conditions in a TextPad 8 file search regular expression? In particular, I want to find all lines in all files that contain the strings Error or Warning, which I can do using the regex error|warning, but in addition to that, I want to select only the subset of those lines where another specified text string, e.g. expir, is not present anywhere on the lines, before or after the location of the matching string from the first regex.

I've tried various forms of putting a conjunction like & or && between the two regexes, but cannot find a syntax that works. Do TextPad regular expressions include support for lookahead and lookbehind zero-width assertions? In perl, I could say


. I entered that in TextPad, and it caused no errors, but it also did not work. It selected all of the lines that contained either error or warning but did not exclude lines that also contained expir.

  • To test if something is NOT present, you have to use this construction: ((?!expir).)* so your regex becomes: ^((?!expir).)*(?:error|warning)((?!expir).)*$ – Toto Sep 20 '17 at 9:47

This regex will find what you want:



^                       : begining of line
    (?=                 : start lookahead
        (?:             : start non capture group
            (?!expir)   : negative lookahead, make sure w don'thave expir
                            You may want to add wordboundaries if you don't want to match "expiration"
            .           : any character but newline
        )*              : group may appear 0 or moe times
        $               : end of line
    )                   : end of lookahead
                            at this point we are sure we don't have "expir" in the line
                            so, go to match the wanted words
    .*                  : 0 or more any character but newline
    (?:                 : start non capture group
        error           : literally error, you could do "\berror\b" if you don't want to match "errors"
        |               : OR
        warning         : literally warning, you could do "\bwarning\b" if you don't want to match "warnings"

With file like:

abc expir 
abc expir warning
abc error expir def

it matches lines 1 and 2 only.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.