In a regular expression, the dot (.) is a metacharacter that matches one character, except a newline. The pattern /.ejected/ therefore matches “dejected,” “rejected,” “%ejected,” and “8ejected.” section 11.3.2 section 11.3
/.ejected/
Test the wildcard against a string whose first character varies. section 11.3.2
The wildcard can admit more matches than intended. Use a character class when the variable position must be restricted to a known set of characters. By default, a newline stops a dot match; the m modifier makes dots match newline characters too. section 11.3.2 section 11.5.4
Matching text across lines
The pattern /\(.*?\)/m captures parenthesized text even when it contains embedded newlines. Without m, the dot reaches the first newline and the match fails when the closing parenthesis is not on that line. section 11.5.4
A dot is special inside a regexp but literal inside an ordinary string. Interpolating that string into a regexp gives the dot wildcard meaning, so Regexp.escape is needed when the interpolated text must match exactly. section 11.3.1 section 11.6.1
