Regex

Installation
SKILL.md

Greedy vs Lazy

  • .* is greedy—matches as much as possible; .*? is lazy—matches minimum
  • Greedy often overshoots: <.*> on <a>b</a> matches entire string, not <a>
  • Default quantifiers + * {n,} are greedy—add ? for lazy: +? *? {n,}?

Escaping

  • Metacharacters need escape: \. \* \+ \? \[ \] \( \) \{ \} \| \\ \^ \$
  • Inside character class []: only ], \, ^, - need escape (and ^ only at start, - only mid)
  • Literal backslash: \\ in regex, but in strings often need \\\\ (double escape)

Anchors

  • ^ start, $ end—but behavior changes with multiline flag
  • Multiline mode: ^ $ match line starts/ends; without, only string start/end
  • \A always string start, \Z always string end (not all engines)
  • Word boundary \b matches position, not character—\bword\b for whole words
Installs
1
First Seen
May 5, 2026