\n- Inside character class `[]`: only `]`, `\\`, `^`, `-` need escape (and `^` only at start, `-` only mid)\n- Literal backslash: `\\\\` in regex, but in strings often need `\\\\\\\\` (double escape)\n\n## Anchors\n\n- `^` start, ` Regex · Skills-SI Market end—but behavior changes with multiline flag\n- Multiline mode: `^` ` Regex · Skills-SI Market match line starts/ends; without, only string start/end\n- `\\A` always string start, `\\Z` always string end (not all engines)\n- Word boundary `\\b` matches position, not character—`\\bword\\b` for whole words\n\n## Character Classes\n\n- `[abc]` matches one of a, b, c; `[^abc]` matches anything except a, b, c\n- Ranges: `[a-z]` `[0-9]`—but `[a-Z]` is invalid (ASCII order matters)\n- Shorthand: `\\d` digit, `\\w` word char, `\\s` whitespace; uppercase negates: `\\D` `\\W` `\\S`\n- `.` matches any char except newline—use `[\\s\\S]` for truly any, or `s` flag if available\n\n## Groups\n\n- Capturing `()` vs non-capturing `(?:)`—use `(?:)` when you don't need backreference\n- Named groups: `(?\u003cname>...)` or `(?P\u003cname>...)` depending on engine\n- Backreferences: `\\1` `\\2` refer to captured groups in same pattern\n- Groups also establish scope for alternation: `cat|dog` vs `ca(t|d)og`\n\n## Lookahead & Lookbehind\n\n- Positive lookahead `(?=...)`: assert what follows, don't consume\n- Negative lookahead `(?!...)`: assert what doesn't follow\n- Positive lookbehind `(?\u003c=...)`: assert what precedes\n- Negative lookbehind `(?\u003c!...)`: assert what doesn't precede\n- Lookbehinds must be fixed-width in most engines—no `*` or `+` inside\n\n## Flags\n\n- `i` case-insensitive, `m` multiline (^$ match lines), `g` global (find all)\n- `s` (dotall): `.` matches newline—not supported everywhere\n- `u` unicode: enables `\\p{}` properties, proper surrogate handling\n- Flags syntax varies: `/pattern/flags` (JS), `(?flags)` inline, or function arg (Python `re.I`)\n\n## Engine Differences\n\n- JavaScript: no lookbehind until ES2018; no `\\A` `\\Z`; no possessive quantifiers\n- Python `re`: uses `(?P\u003cname>)` for named groups; no `\\p{}` without `regex` module\n- PCRE (PHP, grep -P): full features; possessive `++` `*+`; recursive patterns\n- Go: RE2 engine, no backreferences, no lookahead—guaranteed linear time\n\n## Performance\n\n- Catastrophic backtracking: `(a+)+` against `aaaaaaaaaab` is exponential—avoid nested quantifiers\n- Possessive quantifiers `++` `*+` prevent backtracking—use when backtracking pointless\n- Atomic groups `(?>...)` don't give back chars—similar to possessive\n- Anchor patterns when possible—`^prefix` is O(1), unanchored `prefix` is O(n)\n\n## Common Mistakes\n\n- Email validation: RFC-compliant regex is 6000+ chars—use simple check or library\n- URL matching: edge cases are endless—use URL parser, regex for quick extraction only\n- Don't use regex for HTML/XML—use a parser; regex can't handle nesting\n- Forgetting to escape user input—regex injection is real; use literal escaping functions\n\n## Testing\n\n- Test edge cases: empty string, special chars, unicode, very long input\n- Visualize with tools: regex101.com shows matches and explains\n- Check which engine documentation you're reading—features vary significantly\n","licenseDocuments":[]}}
La interfaz está localizada; las descripciones y documentos de las Skills se traducen automáticamente con IA a su idioma. El código, los comandos, rutas y términos técnicos se mantienen en el original, y prevalece el documento del autor.
Explorar Skills
Productividad · SKILL.md

Regex

Regex

Write correct, efficient regular expressions across different engines.

Independent GitHub snapshot · Automated classification · Original documentation governs

Documentación de la Skill

GitHub

name: Regex slug: regex version: 1.0.0 description: Write correct, efficient regular expressions across different engines. homepage: https://clawic.com/skills/regex metadata: clawdbot: emoji: 🔍 os: - linux - darwin - win32 displayName: Regex

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

Character Classes

  • [abc] matches one of a, b, c; [^abc] matches anything except a, b, c
  • Ranges: [a-z] [0-9]—but [a-Z] is invalid (ASCII order matters)
  • Shorthand: \d digit, \w word char, \s whitespace; uppercase negates: \D \W \S
  • . matches any char except newline—use [\s\S] for truly any, or s flag if available

Groups

  • Capturing () vs non-capturing (?:)—use (?:) when you don't need backreference
  • Named groups: (?<name>...) or (?P<name>...) depending on engine
  • Backreferences: \1 \2 refer to captured groups in same pattern
  • Groups also establish scope for alternation: cat|dog vs ca(t|d)og

Lookahead & Lookbehind

  • Positive lookahead (?=...): assert what follows, don't consume
  • Negative lookahead (?!...): assert what doesn't follow
  • Positive lookbehind (?<=...): assert what precedes
  • Negative lookbehind (?<!...): assert what doesn't precede
  • Lookbehinds must be fixed-width in most engines—no * or + inside

Flags

  • i case-insensitive, m multiline (^$ match lines), g global (find all)
  • s (dotall): . matches newline—not supported everywhere
  • u unicode: enables \p{} properties, proper surrogate handling
  • Flags syntax varies: /pattern/flags (JS), (?flags) inline, or function arg (Python re.I)

Engine Differences

  • JavaScript: no lookbehind until ES2018; no \A \Z; no possessive quantifiers
  • Python re: uses (?P<name>) for named groups; no \p{} without regex module
  • PCRE (PHP, grep -P): full features; possessive ++ *+; recursive patterns
  • Go: RE2 engine, no backreferences, no lookahead—guaranteed linear time

Performance

  • Catastrophic backtracking: (a+)+ against aaaaaaaaaab is exponential—avoid nested quantifiers
  • Possessive quantifiers ++ *+ prevent backtracking—use when backtracking pointless
  • Atomic groups (?>...) don't give back chars—similar to possessive
  • Anchor patterns when possible—^prefix is O(1), unanchored prefix is O(n)

Common Mistakes

  • Email validation: RFC-compliant regex is 6000+ chars—use simple check or library
  • URL matching: edge cases are endless—use URL parser, regex for quick extraction only
  • Don't use regex for HTML/XML—use a parser; regex can't handle nesting
  • Forgetting to escape user input—regex injection is real; use literal escaping functions

Testing

  • Test edge cases: empty string, special chars, unicode, very long input
  • Visualize with tools: regex101.com shows matches and explains
  • Check which engine documentation you're reading—features vary significantly
Skills guardadas