regexvbavba7vba6

Match any character except '


I want to match any character (case insensitive) except when preceded by a single quote followed by the text On Error Goto:

Match:

on error goto err_handler
if aap = 0 then on error goto Myerrorhandler
    on error goto errorhandler1
   on error goto errorhandler2

Do not match:

' on error goto errorhandler3
'   if aap =0 then on error goto errorhandler4
Any line not containing On Error Goto

I tried: [^']*(On Error Goto) but that didn't work.

It is to test if an Errorhandler is used in procedures

Thanks!


Solution

  • Use

    ^[^'\n\r]*On Error Goto
    

    Use i case insensitive mode and m multiline mode. See proof.

    Explanation

    --------------------------------------------------------------------------------
      ^                        the beginning of the string
    --------------------------------------------------------------------------------
      [^'\n\r]*                any character except: ''', '\n' (newline),
                               '\r' (carriage return) (0 or more times
                               (matching the most amount possible))
    --------------------------------------------------------------------------------
      On Error Goto            'On Error Goto'