RegExps Flashcards
what two literals are used to create reflexes?
/…/ and %r{…}
What is the basic pattern matching operator
=~
Which method returns a MatchData object?
match( )
How would you write an expression to return a match of “st” in “haystack”?
/st/.match('haystack') # ==> #
What are the 10 metacharacters?
(, ), [, ], {, }, ., ?, +, *
What do character classes represent ??
They list characters that may appear at a certain point in the match.
Within a character class, what metacharacter denotes an inclusive range of characters?
[a-z][0-9]
How do you invert a character match?
Use the ^ (caret) before the character
What does inverting the character match do?
It matches any character except the one inverted
How can you set an intersection of character classes?
/[a-w]&&[^c-g]z]/
Any character except a newline
/./
Any character
/./m (m enables multiline mode)
A word character
/\w/ ([a-zA-Z0-9_])
a NON word character
/\W/ ([^a-zA-Z0-9_])
A digit character
/\d/ ( [0-9] )