The Special Characters and Symbols Within Regular Expressions are listed in the following table.
Character | Meaning |
---|---|
^ | Anchor for the beginning of a line |
$ | Anchor for the end of a line |
\A | Anchor for the start of a string |
\Z | Anchor for the end of a string |
. | Any character |
\w | Any letter, digit, or underscore |
\W | Anything that \w doesn't match |
\d | Any digit |
\D | Anything that \d doesn't match (non-digits) |
\s | Whitespace (spaces, tabs, newlines, and so on) |
\S | Non-whitespace (any visible character) |
To match only letters and digits:
"This is a test".scan(/\w\w/) { |x| puts x }