I want to capture a pattern upto but not including the first instance of an optional other pattern with preg_match, eg:
ABCDEFGwTW$%
You can have the result with a lot less confusion:
Just check a simpler version of the pattern to match, and if not, use the original string: