Skip to content

Instantly share code, notes, and snippets.

@kevinthompson
Last active December 19, 2015 15:38
Show Gist options
  • Save kevinthompson/5977430 to your computer and use it in GitHub Desktop.
Save kevinthompson/5977430 to your computer and use it in GitHub Desktop.
An example of a commented regex block encapsulated in a method.
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
Copy link

def regex
  %r{
    \d4^             # FREAKING MAGIC I DONT KNOW
  }ix
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment