# Ode to Regular Expressions

Robert loves regular expressions and ever since his friend Jean introduced him to Regex Golf, he spends most of his time trying to find the shortest and most elegant solution possible. Robert is also very well-organized and likes to keep an archive containing all his regular expressions along with the test cases accompanying them.

For example [^ad]+ is his neuest regex. It matches the titles from every book in the Lord of the Rings trilogy:

• The Fellowship of the Ring
• The Two Towers
• The Return of the King

and none from the A Song of Ice and Fire series:

• A Game of Thrones
• A Clash of Kings
• A Storm of Swords
• A Feast for Crows
• A Dance with Dragons
• The Winds of Winter
• A Dream of Spring

However, he just noticed that he is missing the test case for his very first (and admittedly messy) regular expression:

Au.+|B[eu].+[ma]|C.+|D.+|E.+|F.+|G.+|H.+|I[rt].+|L.[tx].+|Mal.+|N.+s|P.+|Ro.+|Sl.+|S.[ae].+|(Un.+)?


Robert being the perfectionist he is desperately wants to remember what this monstrosity was even supposed to match, can you help him?

• The Lord of the Rings is actually 3 volumes with 2 books in each. The titles you have listed are the titles of the volumes. #pedantic Jan 11 '17 at 19:13
• @IanMacDonald I just checked on my bookshelf and it turns out you are right. Though to be fair, it is easy to be overlooked Jan 11 '17 at 19:20

I think this regular expression matches ...

... the members of the European Union in a list of all European countries.

Explanation:

The vertical bar denotes alternatives, so if any of the patterns between bars match, the whole expression matches:

Au.+ → Austria
B[eu].+[ma] → Belgium, Bulgaria
C.+ → Croatia, Cyprus, Czech Republic
D.+ → Denmark
E.+ → Estonia
F.+ → Finland, France
G.+ → Germany, Greece
H.+ → Hungary
I[rt].+ → Ireland, Italy
L.[tx].+ → Latvia, Lithuania, Luxembourg
Mal.+ → Malta
N.+s → Netherlands
P.+ → Poland, Portugal
Ro.+ → Romania
Sl.+ → Slovakia
S.[ae].+ → Spain, Sweden
(Un.+)? → United Kingdom

Simple patterns like E.+ mean there is no ambiguity. More complex patterns must select EU members over non-EU members, e.g. none of the S pattern matches Switzerland.

• Australia and Canada are both included, though. Jan 11 '17 at 19:14
• Yes, but that's not a European country. Jan 11 '17 at 19:14
• Define "European country". Both of those are members of the British commonwealth. ;) Jan 11 '17 at 19:15
• Aristotelian physics say that a country that is even its own bloody continent can't be European. :) Jan 11 '17 at 19:19
• And the typo hint, neuest gives nEUest Jan 11 '17 at 19:40