The regex | (or) operator splits the pattern left or right unless explicitly grouped.
Group it using (pattern) if you need to use the match later,
or as a non-capturing group (?:pattern) if you do it for clarity.
I used to think there was some magic rule about how | decided where to split,
but it’s simply: characters and subpatterns concatenate into a single pattern first,
then | splits the entire thing left and right unless you explicitly group it.
That’s because | has the lowest precedence so all other operations happen first.
So while I used to think that prefix_cat|dog would match prefix_cat and prefix_dog,
it actually matches prefix_cat and then dog.
And that exact problem in a real-world example, to find if a page is linking to another, both relative or full URL:
[… more]