Since I always forget some important things about Regex, I’ll write it down here:
Greedy vs Non-Greedy
If you have something like “hello|world|!” and you want to get only the first part before the first Delimiter (which obviously is “|”) your first try could look like:
That one would match “hello|world” since by default Regex is Greedy (aka. “take as much as possible”).
The old-fashioned way was:
This one does match unless the “|” Sign is found.
Now Regex has a much nicer solution:
The added “?” makes it Non-Greedy (aka. “take as less as possible)
Sometimes you want to create a Group which is not captured. Just begin those Groups with an “?:” and it will not get captured.