Updated link to regex test cases: https://regex101.com/r/UYll0h/6
Since there can be no character when '
isn't there, therefore you will need to use a look-ahead assertion.
Since there can also be other characters of the code (other than '
) in the line before on error goto
(like in the line if aap = 0 then on error goto Myerrorhandler
), to handle those, you will also need to put a condition to check if any character other than '
is present after the look-ahead. This will be done by ([^']+)?
.
^(?!')([^']+)?on error goto
The (?)
is called a look-ahead. It checks if the characters inside it are present or not. Unlike []
, (?)
will assert true even when there are no characters. So for example, [a]
will check if the first character is 'a', but any expression after it will check from the second character. On the other hand, (?=a)
will check if the first character is 'a', and any expression after it will check from the first character. In other words, the look-ahead doesn't move the regex engine to the next character if a match is not found.