Regex (regular expressions) are a special datatype in Ruby that allows you to declare a pattern that can be used to match other objects like strings. This is an example of declarative programming that we talked about earlier in the week, because you're just specifying the results that you'd like to see, not telling the computer how to do it.
Fork/clone this repo. In the end, do a pull request (PR) to turn in the assignment.
Run bundle install
from the terminal in this folder to ensure that you have
the proper Gems installed.
- Use
@source_text
as your data source for extracting data. Do not edit this file. - Extract all valid IP addresses into an array returning from the
valid_ip_addresses
method- (format for valid IP address is xxx.xxx.xxx.xxx)
- Extract all valid IP addresses from MIT into an array returning from the
valid_mit_ip_addresses
method- (format 18.xxx.xxx.xxx)
- From this data, create an array of non-MIT IP addresses from the
non_mit_ip_addresses
method - Extract unique valid US phone numbers into an array returning from the
valid_phone_numbers
method - Extract the valid area code into an array returning from the
area_codes
method.- (US area codes cannot begin with 0 or 1)
- Extract the email addresses into an array returning from the
email_addresses
method.- (format X@Y.Z)
- Extract the valid zip codes into an array returning from the
zip_codes
method. - Extract the valid hex colors into an array returning from the
hex_colors
method.
Run rspec spec
to check if your main.rb
has the right results.
Quick blog post on Regexes:
http://www.joshondesign.com/2011/04/12/joshs-quick-intro-to-regex/
Rubular - an awesome real-time regex editor for Ruby
RegExr - another regex editor, rollover an expression or match to see a detailed explanation