Reference

Regex Syntax Cheat Sheet

Regex syntax notes for parsing logs, IDs and API text fields.

Overview

Regular expressions help inspect copied logs, request IDs, slugs, tokens and structured text. This reference focuses on JavaScript regex behavior because it matches what browser-based debugging tools and many frontend applications use.

Debugging Reference Table

SyntaxMeaningDebugging note
.Any character except line breakUse carefully; it can match more than expected.
\dDigitUseful for IDs, timestamps and status-like values.
\wWord characterDoes not mean every Unicode letter.
+One or moreGreedy by default.
*Zero or moreCan match empty strings.
?Optional or lazy modifierMeaning depends on position.
^ / $Start / end anchorMultiline behavior changes with the m flag.
(...)Capture groupUse when you need part of a match.
(?:...)Non-capturing groupUseful for grouping without extra captures.
(?=...)LookaheadUseful for conditions without consuming text.

Reference Table Coverage

  • JavaScript regex syntax.
  • Greedy versus precise matching.
  • Flags such as g, i and m.
  • Log and request ID extraction.

API Debugging Examples

  • Extract request IDs from copied API logs.
  • Find all user IDs in a payload fragment.
  • Check whether a slug pattern rejects unexpected characters.

Common Mistakes

  • Forgetting the global flag when expecting multiple matches.
  • Writing greedy patterns that capture too much text.
  • Confusing regex escaping in JavaScript strings and literals.
  • Assuming \w covers every human-language character.

FAQ

Why does my regex match too much?

Greedy quantifiers such as .* and .+ consume as much text as possible. Use narrower character classes or lazy quantifiers when appropriate.

Why do I only get one match?

In JavaScript, multiple matches usually require the g flag or repeated matching logic.

Should regex parse full JSON?

No. Use JSON parsing for JSON data; regex can help locate snippets or IDs in logs.