Match this OR that
The pipe character | means OR. cat|dog matches either the substring 'cat' or the substring 'dog'. The engine tries each alternative left to right; first match wins.
Order matters
Most regex engines are not longest-match — they're first-match. Pattern cat|cats against 'cats' matches just 'cat' because that's tried first. To match the longer one, put it first: cats|cat.
This is the opposite of awk's POSIX longest-match behavior. Most engines you'll use (Python, JS, PCRE) follow first-match.
Always group your alternation
Without parentheses, alternation extends as far as it can in both directions. Pattern cat|dog alone is fine. But pattern my cat|dog means "my cat" OR "dog" — not "my (cat or dog)." To get the latter, wrap: my (?:cat|dog).
This is the #1 alternation bug in beginner regex.
Performance: alternation is expensive
The engine tries every alternative against every position. For long lists, character classes are dramatically faster: [abcde] beats (?:a|b|c|d|e). Use alternation for multi-character alternatives that don't fit in a class.