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
| Syntax | Meaning | Debugging note |
|---|---|---|
| . | Any character except line break | Use carefully; it can match more than expected. |
| \d | Digit | Useful for IDs, timestamps and status-like values. |
| \w | Word character | Does not mean every Unicode letter. |
| + | One or more | Greedy by default. |
| * | Zero or more | Can match empty strings. |
| ? | Optional or lazy modifier | Meaning depends on position. |
| ^ / $ | Start / end anchor | Multiline behavior changes with the m flag. |
| (...) | Capture group | Use when you need part of a match. |
| (?:...) | Non-capturing group | Useful for grouping without extra captures. |
| (?=...) | Lookahead | Useful 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.