Last active
December 19, 2015 15:38
-
-
Save kevinthompson/5977430 to your computer and use it in GitHub Desktop.
An example of a commented regex block encapsulated in a method.
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
def email_pattern | |
%r{ | |
^[A-Z0-9._%+-]+ # Beginning with one or more valid characters (letters, numbers, period, etc.) | |
@ # A literal "at" sign | |
[A-Z0-9.-]+ # One or more letters, numbers, period, or dash | |
\. # A literal period | |
[A-Z]{2,4}$ # Ending with a two to four character text domain extension | |
}ix # Flags: Ignore whitespace and ignore letter case | |
end | |
'[email protected]'.match(email_pattern) # => #<MatchData "[email protected]"> | |
'[email protected]'.match(email_pattern) # => #<MatchData "[email protected]"> | |
'planningcenteronline.com'.match(email_pattern) # => nil |
danielmurphy
commented
Jul 25, 2013
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment