I want to capture a pattern upto but not including the first instance of an optional other pattern with preg_match, eg:
ABCDEFGwTW$%
Try this: (.*?)(?:EFG|$)
(.*?)(?:EFG|$)
This will match any character (as few as possible) until it finds EFG.