Ruby - Regular Expressions Special Characters and Symbols

Introduction

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
\AAnchor for the start of a string
\ZAnchor for the end of a string
. Any character
\wAny letter, digit, or underscore
\WAnything that \w doesn't match
\dAny digit
\DAnything that \d doesn't match (non-digits)
\sWhitespace (spaces, tabs, newlines, and so on)
\SNon-whitespace (any visible character)

To match only letters and digits:

Demo

"This is a test".scan(/\w\w/) { |x| puts x }

Result