Created
May 11, 2017 09:35
-
-
Save rlisowski/8b1075baf2a2a359df5b1185c1ebcf96 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| regex = Regexp.new(/^[0-9]* (.*), (.*) [a-zA-Z]{2} [0-9]{5}(-[0-9]{4})?$/) | |
| addresses = ["420 Fanboy Lane, Cupertino CA 12345"] | |
| addresses << "1829 William Tell Oveture, by Gioachino Rossini 88421" | |
| addresses << "114801 Western East Avenue Apt. B32, Funky Township CA 12345" | |
| addresses << "1 Infinite Loop, Cupertino CA 12345-1234" | |
| addresses << "420 time!" | |
| addresses.each do |address| | |
| print address | |
| if address.match(regex) | |
| puts " is an address" | |
| else | |
| puts " is not an address" | |
| end | |
| end | |
| # Outputs: | |
| > 420 Fanboy Lane, Cupertino CA 12345 is an address | |
| > 1829 William Tell Oveture, by Gioachino Rossini 88421 is not an address | |
| > 114801 Western East Avenue Apt. B32, Funky Township CA 12345 is an address | |
| > 1 Infinite Loop, Cupertino CA 12345-1234 is an address | |
| > 420 time! is not an address |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment