[Question]
  [
We've already got a [meta-regex-golf problem](https://codegolf.stackexchange.com/q/17718/2180) as inspired by the xkcd comic
![copyright 2013 Randall Munroe](https://imgs.xkcd.com/comics/regex_golf.png)
But, this regex golf looks fun, too! I want to distinguish between the states of the US and the regions of Italy. Why? I'm a citizen of both countries, and I always have trouble with this\*.
The regions of Italy are
```
Abruzzo, Valle d'Aosta, Puglia, Basilicata, Calabria, Campania, Emilia-Romagna, Friuli-Venezia Giulia, Lazio, Liguria, Lombardia, Marche, Molise, Piemonte, Sardegna, Sicilia, Trentino-Alto Adige/Südtirol, Toscana, Umbria, Veneto
```
and the states of the USA are
```
Alabama, Alaska, Arizona, Arkansas, California, Colorado, Connecticut, Delaware, Florida, Georgia, Hawaii, Idaho, Illinois, Indiana, Iowa, Kansas, Kentucky, Louisiana, Maine, Maryland, Massachusetts, Michigan, Minnesota, Mississippi, Missouri, Montana, Nebraska, Nevada, New Hampshire, New Jersey, New Mexico, New York, North Carolina, North Dakota, Ohio, Oklahoma, Oregon, Pennsylvania, Rhode Island, South Carolina, South Dakota, Tennessee, Texas, Utah, Vermont, Virginia, Washington, West Virginia, Wisconsin, Wyoming
```
Your job is to write a program which distinguishes these lists with a regular expression. This is a new game, so here's the
**Rules**
* Distinguishing between lists must be done with a single matching regular expression.
* Your score is the length of that regular expression, smaller is better.
To be clear: all work must be done by the regular expression -- no filtering, no replacements, no nothing... even if those are also done with regular expressions. That is, the input should be passed directly into a regular expression, and only the binary answer (match / no match) can be used by later parts of the code. The input should never be inspected or changed by anything but the matching expression. *Exception*: eating a newline with something akin to Ruby's `chomp` is fine.
Your program should take a single entry (optionally followed by `\n` or `EOF` if it makes things easier) from either list from stdin, and print to stdout the name of that list. In this case, our lists are named `Italy` and `USA`.
To test your code, simply run both lists through it. Behavior may be undefined for strings which do not occur in the list.
**Scoring Issues**
This might have to be done on a language-by-language basis. In Perl,
```
m/foobarbaz/
```
is a matching regular expression. However, in Python,
```
import re
re.compile('foobarbaz')
```
does the same thing. We wouldn't count the quotes for Python, so I say we don't count the `m/` and final `/` in Perl. In both languages, the above should receive a score of 9.
To clarify a point raised by [Abhijit](https://codegolf.stackexchange.com/users/7638/abhijit), the actual length of the matching expression is the score, even if you generate it dynamically. For example, if you found a magical expression `m`,
```
n="foo(bar|baz)"
m=n+n
```
then you should not report a score of 12: `m` has length 24. And just to be extra clear, the generated regular expression can't depend on the input. That would be reading the input before passing it into the regular expression.
**Example Session**
```
input> Calabria
Italy
input> New Hampshire
USA
input> Washington
USA
input> Puglia
Italy
```
\* Actually, that's a lie. I have never had any trouble with this at all.
  
[Answer]
# Perl - ~~51~~ 36 bytes (for regex)
```
print<>=~/.A|ise|net|te|z.o|[cp]a|[lr]ia|r[cd]/?"Italy
":"USA
"
```
~~Nothing special, but may as well post it, because it's different to other 51 bytes solution.~~
Or alternatively, shorten my already short solution by 15 bytes. This wins for now, I think.
[Answer]
## Perl, 40 chars
Approaching this from the other direction, i.e. matching the U.S. states:
```
[DNIOWy]|ss|M.n|^A.*a|or|[aguh]i|[sth]\b
```
The only Perl/PCRE-specific feature in the regexp is the `\b` word boundary anchor, which I used instead of the `$` end-of-string anchor to let it match "South Carolina".
Here's the regexp in a Perl one-liner for testing:
```
perl -nE 'say /[DNIOWy]|ss|M.n|^A.*a|or|[aguh]i|[sth]\b/ ? "USA" : "Italy"'
```
[Answer]
# Regex ([POSIX ERE](https://en.wikibooks.org/wiki/Regular_Expressions/POSIX-Extended_Regular_Expressions)), 28 bytes
Matching the regions of Italy:
```
[eldrz]..$|[cpVS]a|-|[hst]e$
```
[Try it online!](https://tio.run/##TVPbTttAEH3ufsUKRaR9MFVfCzykoUAKAYQhqIqiauKd2qOsd9LdNSGWP61v/bB01qEXy9KeueyZOTP2EkK18whGZ97o4VD7k5Pht9dnuJujNb5dHB0NunmxnuUL6LJuXoW4wMHuT5raVGRRT87zU/1KpW3XzXXm9MHAHujFsWH1RuxWD4JedB0WFR@H0w/HvW@f03Vvk7u3Oiw9rnX2A8X0B/rwUPcxIZxEsNuP@ztd99f9mI/2znfKsMPdaOmbtmU1AyutmeGIQwR115SWQH2CQJYKEM8YLCw9JVCvwQn4XEsMsnuuoXSgzj01lrIZOmwJ9EWyQF1DS6yuqWzS3Wuul@CNoCn4okI1ZUsB1R1hzS6iyiWKiS2nIrGrB48ukuNsZCPrkaES3@e/fppInq164FCAZD/WfWupdmSlRtIq1JDOsJLDU8sunStwAULSQt/ZJxFjtuxBpj5m57CIVDRRnaGFDXhU5xIkA@oC2ZeSfSluIjUxULGaWCuNUVATJ4qEf8IbUFf7ElfSdlOstiK5odCHp0AOk/CtBWcEhABF1QSMMagpFRWV4ARIH4Fl4lMKIb3rNfWYZYQyMBcT2Q0ufS/uBp/BpGOjL2UzoSLpO1lf0Afc9nCKL1RwD7@yX6kb9rHSY5ARUuLqzTNYpaq3lezrdmVFoUzw1mPJTt2hc2Frn/u931ds5CMOvYqcm/@p9uYr1QMmKQFR0IvM5DFCJTvyadVqRjLRRPckPxa5MkqZJwxR/wtQKNgFEv@Wa0n5DQ "Bash – Try It Online")
Since we're being scored on the length of the pure regex, it just makes sense to show that alone above. The TIO test harness uses bash and egrep, but practically any regex engine would work. The only thing that makes this require POSIX ERE instead of POSIX BRE are the unescaped `|` alternative separators. Here is a bash oneliner to apply it:
```
egrep -q '[eldrz]..$|[cpVS]a|-|[hst]e$'&&echo Italy||echo USA
```
I used [regexp-golf-coffeescript](https://github.com/amitayd/regexp-golf-coffeescript.git), with a little parameter tuning, to brute-force this.
You can experiment with deleting characters from the character classes or deleting alternatives in the TIO to see how many correct matches are lost by doing so. For many, it's just one each.
There may be further optimization possible. The script I used only searches the space in which a single character class is used per alternative, but some regex golf problems of this type benefit from multiple character classes in a single alternative, like `[bgr].[ei]`. However, given the characteristics of this data set, I expect that the benefit, if any, would probably be no more than a couple bytes.
# Regex ([POSIX ERE](https://en.wikibooks.org/wiki/Regular_Expressions/POSIX-Extended_Regular_Expressions)), 41 bytes
Matching the states of the USA:
```
[IfKNOWwhy]..|[kamed].$|t$|iz|ta.|[guaM]i
```
[Try it online!](https://tio.run/##TVPbbtswDH2evkIogmV7SIe9ru1Dlq6t1zopml4wFMHA2KxNWBYzSW5qw5@2t31YRjndxTCgw4sOeUh7Db7cOYRcT1yux2Ptjo/H31@f8e4xebqcLx62Zbs6POwfK6gxXx2O@jDqqesDiK9oIF3R7s8dtS3JoE7Olif6lVebvn/UE6sPRuZAr45yVm/E7vTI61XfY1bykT/5eDT49jl9/y66B6vHwuFGT36gmO5Av32rh5gQ3i2nn/Y3@v6vMwlg2r37vcrZ4m66dk3XsboHI63l4yn7AOq6KQyB@gyeDGUgnhkYWDuKoN6AFfCllhhMbriGwoI6c9QYmtyjxY5An0cL1BV0xOqKiibeveJ6DS4XlILLSlQpG/KorglrtgHVUqIY2ZaURXZ169AGsjyZmsB6mlOBH5a/fuaBHBt1yz4Dyb6rh9Zi7cBKTaVVqCGevpLDUcc2nhVYDz5qoSd2UcSMDTuQqc/YWswCZU1Qp2hgCw7VmQQpB3WO7ArJvhA3kUpyKFklxkhj5FViRZHwJ7wFdbkvcSltN1nViuSG/BBOgSxG4a0BmwvwHrKy8RiCVyllJRVgBUgfnmXiKXkf382GBswyQhmYDZFsjms3iJvjM@Tx2OoL2YwvSfqO1ld0HtsBpvhCGQ/wG7tKzdmFUs9ARkiRazBPoYpVF6Xsa1EZUSgTXDgs2KprtNa35nnY@03JuXzEflCx5OZ/qr35SnWLUYpHFPQiM7kLUMqOXFy1uieZaKR7kL@MbBGkzAP6oP8FyGdsPYm/5VpSfgM "Bash – Try It Online")
[Answer]
# Ruby (plain regex), 44
```
$_ = gets.chomp
puts /'|-|(([^gn]i|gn|at)a|[hst]e|to|zo)$|To|La|pa/ ? "Italy" : "USA"
```
You know what? Case sensitivity is the best start-of-word anchor.
I'm not sure, but I think I owe the `pa` to [Hax0r778's answer](https://codegolf.stackexchange.com/a/17859/7209).
[Answer]
## Perl - 51
```
(<STDIN> =~ m/'|-|ru|pu|at|pa|az|gu|mb|rc|ie|rd|ci|os|abr|mol|ven/)?printf("Italy\n"):printf("USA\n");
```
[Answer]
# JavaScript 42
`alert(/at|gn|mp|sc|-|'|((zi?|t)o|[hts]e|[lrd]ia)$/g.test(prompt())?"Italy":"USA")`
I was initially going to work this out from the USA side, as eliminating KWXY from the USA list strips a lot of the States away... But Italy had it bested by a good 17 characters...
If we go with fat arrow notation we can reduce this to a simple function with a return variable.
`r=s=>/at|gn|mp|sc|-|'|((zi?|t)o|[hts]e|[lrd]ia)$/g.test(s)?"Italy":"USA"`
```
> r("South Dakota") // USA
> r("Puglia") // Italy
```
]