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 \Aalways string start,\Zalways string end (not all engines)- Word boundary
\bmatches position, not character—\bword\bfor whole words