Regular Expression Cheat Sheet for Search, Extraction and Replacement
A practical reference for regular-expression character classes, groups, quantifiers, boundaries and replacement workflows.
What this reference covers
This sheet organizes regular expressions around character classes, quantifiers, groups, boundaries and replacement expressions. It is useful when a script, log query, editor or data-cleaning task needs a compact pattern reference.
Define the target and counterexamples before writing a long pattern. Regex engines differ in escaping, Unicode, line breaks and backtracking, so a pattern should be tested in the same language or tool that will run it.
A repeatable test loop
Start with literal text, add one structure at a time, and keep successful and unsuccessful samples together. Review captured groups and replacement output on a copy before changing the original data.
Maintenance note
This is a quick reference rather than a cross-language compatibility guarantee. For external input, set length and execution limits and avoid using one pattern as a substitute for a structured parser. Content review date: 2026-08-23.
Save to your cloud drive
Save the complete collection first so files remain together and are easier to access across devices.
Quark Cloud Drive
RecommendedSave Regular Expression Cheat Sheet for Search, Extraction and Replacement to this cloud drive
Baidu Netdisk
Save Regular Expression Cheat Sheet for Search, Extraction and Replacement to this cloud drive
Regular expression matching and replacement study guide
Describe the expected text, build the smallest matching pattern, test boundaries and captures, then review replacement output before applying it to real data.
Before you start
- Prepare a PDF reader and a small set of sanitized text samples.
- List at least three expected matches and three counterexamples.
- Note the language or editor regex engine that will run the pattern.
Quick start
- 01
Define the matching target
Write the text to find or reject in plain language, including spaces, line breaks and optional fields.
- 02
Build from literal text
Match fixed text first, then add character classes, groups and quantifiers one at a time.
- 03
Check boundaries and captures
Test start and end boundaries, greedy behavior and each capture group against both positive and negative samples.
- 04
Preview the replacement
Run replacement on a copy, inspect every captured value and confirm that unmatched content stays unchanged.
Usage tips
- Record engine, Unicode mode, line-break mode and maximum input length with the pattern.
- Keep complex patterns commented and preserve a small regression sample.
- Use a structured parser for HTML, JSON, code or other nested formats.
Troubleshooting and uninstall
Why does a pattern match too much text?
Check greedy quantifiers, missing boundaries and group scope; reduce the pattern to the smallest matching fragment before widening it.
Why do two tools return different results?
Compare the regex engine, escaping rules, Unicode mode and newline settings, then run the same sample in both tools.
Frequently asked questions
What is a regular expression best suited for?
It works well for searching, extracting, replacing and basic validation in relatively stable text, but it should not replace a parser for nested or context-sensitive formats.
Why keep counterexamples?
Successful samples alone can hide an overly broad pattern; counterexamples expose boundary, whitespace, newline and optional-field mistakes.
What should be checked before using a pattern in production?
Check the engine, encoding, input length, execution time, replacement preview and handling of malformed or sensitive input.