If a regular expression contains “|” operators, the left most matching sub-expression is chosen. Example: if the regular expression is ‘(cat|dog)’ and the target string is ‘cats and dogs’, the match succeeds with ‘cat’ after the first three letters have been scanned.
In “*”, “+”, and “?” constructs, longer matches are chosen in preference to shorter ones. Example: if the regular expression is ‘^He’s ba*’ and the target string is ‘He’s baaaaack!’, the match succeeds with ‘He’s baaaaa’ after the full list of contiguous a’s have been scanned.