Could be 3 types of components

  • Literal characters, meaning “match this character”
  • The dot wildcard character (.), meaning “match any character” (except \n, the newline character)
  • Character classes, meaning “match one of these characters”
SymbolMeaning
//, %r{} Instances of Regexp class
=~ Determines if a match exists
. Matches any character except \n
\Escape character; tells Ruby to treat the next character as a literal
[ ]Surrounds a character class; matches either character between [ and ]
^ 1. Negates a character or character class; matches anything except what follows ^
2. Matches the expression at the start of a line
\dMatches any digit
\DMatches any digit, alphabetical character, or underscore
\w Matches any digit, alphabetical character, or underscore
\W Matches anything except a digit, alphabetical character, or underscore
\s Matches any whitespace character (space, tab, newline)
\SMatches anything except a whitespace character (space, tab, newline)
{ }Matches a character or character class a specific number of times
$Matches the expression at the end of a line
+Matches one or more occurrences of the character or character class
*Matches zero or more occurrences of the character or character class
artpes57

Author artpes57

More posts by artpes57

Leave a Reply

All rights reserved Salient.