Regex quick reference (hover/tap for details)
-
[abc]a|b|c[abc]matches one of a, b, or c.Example: “cab” → matches “c”, “a”, or “b”.
-
[^abc]not a|b|c[^abc]matches any char except a, b, or c.Example: “dog” → “d”, “o”, “g” match; “a” doesn’t.
-
[a-z]a..z[a-z]matches a lowercase letter.Example: “ruby” → every letter matches.
-
[a-zA-Z]letter[a-zA-Z]matches any letter.Example: “v2” → matches “v”, not “2”.
-
^start^is start of line.Example:
^Hionly at the beginning. -
$end$is end of line.Example:
done$only at the end. -
\Astr start\Ais start of string (not just line).Example:
\AHimatches only once at very start. -
\zstr end\zis end of string.Example:
ok\zmatches only at very end. -
.any.matches any char (except newline unlessm).Example: “cat” → “.” can be “c”, “a”, or “t”.
-
\sspace\swhitespace: space, tab, newline.Example: “a b” → matches the space.
-
\Snon‑space\Sany non‑whitespace.Example: “ a” → matches “a”, not the space.
-
\Rline break\Rany linebreak.Example: “\n” → matches newline.
-
\ddigit\ddigit 0–9.Example: “v2” → matches “2”.
-
\Dnon‑digit\Dany non‑digit.Example: “v2” → matches “v”, not “2”.
-
\wword\wletter/number/underscore.Example: “a_b” → matches “a”, “_”, “b”.
-
\Wnon‑word\Wnot letter/number/_.Example: “a-b” → matches “-”.
-
\bboundary\bword boundary.Example:
\bcat\bfinds “cat” as a whole word. -
(...)capture(...)capture group.Example:
(ab)+captures repeats of “ab”. -
(a|b)eithera|balternation: a or b.Example:
(cat|dog). -
a?0 or 1 timesa?zero or one “a”.Example:
colou?rmatches “color”/“colour”. -
a*0+ timesa*zero or more “a”.Example: “ba*” → “b”, “ba”, “baaa”.
-
a+1+ timesa+one or more “a”.Example: “ba+” → “ba”, “baaa” (not “b”).
-
a{3}3× timesa{3}exactly three “a”.Example: matches “aaa”.
-
a{3,}3+ timesa{3,}three or more.Example: “aaa”, “aaaa”, …
-
a{3,6}3–6 timesa{3,6}between three and six.Example: matches “aaa”..“aaaaaa”.
Options (hover/tap for details)
-
iignore caseimakes matches case‑insensitive.Example:
/cat/imatches “Cat” and “cat”. -
mdot = newlinemmakes.match newline too.Example:
/a.b/mcan span lines. -
xfree‑spacingxignores spaces and# commentsin regex.Example:
/( \d+ ) # number/x -
o#{ } onceointerpolates#{...}only once.Example:
/#{Time.now}/okeeps the first value.