Catalog / Regex and Text Manipulation Cheat Sheet
Regex and Text Manipulation Cheat Sheet
A comprehensive cheat sheet covering regular expressions and text manipulation techniques. Learn how to effectively search, extract, and modify text using various tools and methods.
Regex Basics
Metacharacters
|
Escapes the next character. |
|
Matches the beginning of the string or line. |
|
Matches the end of the string or line. |
|
Matches any single character except newline. |
|
Alternation (OR operator). |
|
Grouping and capturing. |
|
Character class (matches any character within the brackets). |
|
Quantifier (specifies how many occurrences to match). |
|
Quantifiers: |
Character Classes
|
Matches any digit (0-9). |
|
Matches any non-digit character. |
|
Matches any word character (a-z, A-Z, 0-9, _). |
|
Matches any non-word character. |
|
Matches any whitespace character (space, tab, newline). |
|
Matches any non-whitespace character. |
|
Matches a, b, or c. |
|
Matches any character except a, b, or c. |
|
Matches any lowercase letter. |
Quantifiers
|
Matches 0 or more occurrences. |
|
Matches 1 or more occurrences. |
|
Matches 0 or 1 occurrence. |
|
Matches exactly n occurrences. |
|
Matches n or more occurrences. |
|
Matches between n and m occurrences (inclusive). |
Advanced Regex
Grouping and Capturing
|
Creates a capturing group. The matched text within the parentheses can be referenced later. |
|
Backreferences to the captured groups. |
(?:pattern) |
Non-capturing group. Groups the pattern but doesn’t capture the matched text. |
Lookarounds
|
Positive lookahead. Matches if the pattern follows the current position, but doesn’t include the pattern in the match. |
|
Negative lookahead. Matches if the pattern does not follow the current position. |
|
Positive lookbehind. Matches if the pattern precedes the current position, but doesn’t include the pattern in the match. |
|
Negative lookbehind. Matches if the pattern does not precede the current position. |
Flags/Modifiers
|
Case-insensitive matching. |
|
Global matching (find all matches instead of stopping after the first). |
|
Multiline mode ( |
|
Dotall mode ( |
Text Manipulation Tools
Common Tools
grep: A command-line tool for searching text using regular expressions. |
Grep Examples
|
|
|
|
|
Sed Examples
|
|
|
|
|
Programming Languages
Python Regex
|
JavaScript Regex
|
Ruby Regex
|