Skip to content

Instantly share code, notes, and snippets.

@sranso
Created February 9, 2014 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sranso/8904441 to your computer and use it in GitHub Desktop.
Save sranso/8904441 to your computer and use it in GitHub Desktop.
(ABC|DE) # => capture ABC or DE, once
(ABC|DE){2} # => capture ABC or DE, exactly two times. can be ABC or DE twice, or each of them once
[ABCDE] # => any of the letters once
.* # => any single character, zero or more times. the letter doesn't have to be the same one...
#for example, "aa" or "ab" will both be matched
[^ABC] # => any character besides ABC
a? # => 0 or 1 of a
a* # => 0 or more of a
a+ # => 1 or more of a
# EXAMPLES
# how many lives does a cat have
/\d .*\./.match("Cats have 9 lives.") # => #<MatchData "9 lives">
# get me that quote and movie
/('.*').*movie (.*)\./.match("Matt Damon said, 'I gotta go see about a girl' in the movie Good Will Hunting.") # => #<MatchData "'I gotta go see about a girl' in the movie Good Will Hunting." 1:"'I gotta go see about a girl'" 2:"Good Will Hunting">
# get me all the super long words
/\S{5,}/.match("run roughshod over nuance") # => #<MatchData "roughshod">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment