Created
February 9, 2014 19:07
-
-
Save sranso/8904441 to your computer and use it in GitHub Desktop.
This file contains 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
(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