in reply to Re^2: a regex pattern how to understand
in thread a regex pattern how to understand

As the other anon already said, the +? modifier makes the expression non-greedy, meaning it doesn't consume all possible characters. Even if the ? is removed, the regular expression still works due to Backtracking:

For a regular expression to match, the entire regular expression must match, not just part of it. So if the beginning of a pattern containing a quantifier succeeds in a way that causes later parts in the pattern to fail, the matching engine backs up and recalculates the beginning part--that's why it's called backtracking.