This topic is for the [Regular Expressions - Tying it all together] exercise in the [Regular Expressions] trail. Post any questions, corrections, or pointers you have to share with other Upcase subscribers.
[Regular Expressions - Tying it all together]: https://exercises.upcase.com/exercises/regular-expressions-advanced
[Regular Expressions]: Regex Tutorials | Regular Expressions Online Tutorial by thoughtbot
For the last test that involves handling “numbers with international codes”, do we solely have to make the +1 test pass? For other countries and depending on what country you’re calling from, it seems like the best way would be to work backwards in order to handle international dialing codes (ex: 001 is the United States, 0086 is China, +359 is Bulgaria, etc).
Hey @ACPK, the problem as written was only looking for the +1
case, but I think your intuition is correct. It is certainly possible to build a regex to cover the majority of phone numbers, it is very difficult to cover all possible variants.
The less “regular” (read “predictable”, “structured”, etc) your input, the worse you’ll find regex as a solution. Check out the When not to use section of the regex weekly iteration for more detail. In those cases you’ll want to look into a proper parser.