Regex Tester Online
Test, debug, and visualize regular expressions with instant match highlighting and multi-language code generation.
Regex Whitespace & Newline Guide
Master regex space characters, blank characters, and line endings with this complete reference. Click any symbol to try it in the tester above.
Whitespace & Newline Reference Table
| Metacharacter | What it Matches | Common Use Case |
|---|---|---|
\\s | Any whitespace: space, tab, newline, carriage return | Clean up input with str.replace(/\s+/g, '') |
\\S | Any non-whitespace character | Extract words: \S+ matches each word |
| Exactly one space character | Match a specific format like first last |
\\t | Horizontal tab | Parse TSV (tab-separated values) files |
\\n | Line feed (Linux/macOS newline) | Split text into lines |
\r\n | Carriage return + line feed (Windows newline) | Parse Windows-format log files |
\\r | Carriage return (classic Mac OS) | Legacy file format handling |
Regex Syntax Demystified
Decode the most searched regex symbols. Click any symbol to insert it into the tester above.
Click to View Full Syntax Table
| Symbol | Name | What it Does | Example |
|---|---|---|---|
^ | Caret (Start anchor) | Matches the beginning of a line or string | ^Hello matches "Hello" only at the start |
$ | Dollar (End anchor) | Matches the end of a line or string | end$ matches "end" only at the end |
? | Question mark | Makes the previous character optional (0 or 1) | colou?r matches "color" and "colour" |
* | Asterisk | Matches 0 or more of the previous character | ab*c matches "ac", "abc", "abbc" |
+ | Plus | Matches 1 or more of the previous character | ab+c matches "abc", "abbc" (not "ac") |
[^abc] | Negated class | Matches any character NOT listed inside brackets | [^0-9] matches any non-digit |
\\b | Word boundary | Matches the position between a word char and non-word char | \bcat\b matches "cat" but not "scatter" |
(...) | Capturing group | Groups part of the pattern for extraction | (\d+)-(\d+) captures area code and number |
Python Regex Cheat Sheet
Quick reference for the most-used re module methods and patterns.
Python re Module Methods
| Method | Purpose | Example |
|---|---|---|
re.search() | Find first match anywhere in string | re.search(r'\d+', 'abc123') # matches "123" |
re.match() | Match only at the beginning of string | re.match(r'Hello', 'Hello World') # matches |
re.findall() | Return all matches as a list | re.findall(r'\d+', 'a1b22c333') # ['1', '22', '333'] |
re.sub() | Replace matches with a string | re.sub(r'\s+', '-', 'a b c') # "a-b-c" |
re.split() | Split string by pattern | re.split(r'[,;]', 'a,b;c') # ['a', 'b', 'c'] |
PowerShell & Grep Quick Reference
| Tool | Task | Command |
|---|---|---|
| grep | Find errors in log files | grep -E 'ERROR|WARN.*timeout' app.log |
| grep | Extract IPs from a file | grep -oE '[0-9]+\\.[0-9]+\\.[0-9]+\\.[0-9]+' access.log |
| grep | Case-insensitive search | grep -i 'error' /var/log/syslog |
| PowerShell | Match pattern in string | "hello 123" -match "\d+" |
| PowerShell | Replace with regex | "a b c" -replace "\s+", " " |
Frequently Asked Questions
Regex how to allow spaces?
To allow spaces in your regular expression, you have two main options. The simplest way is to just type a literal space character in your pattern (e.g., hello world). However, the most robust way to match a regex space character or any regex blank character is to use the metacharacter \s. This will match standard spaces, tabs, and line breaks.
What is the regex for new line?
The standard regex for new line is \n. If you are working with Windows-formatted text, a new line might be represented by a carriage return followed by a line feed, which is written as \r\n. To match the end of a line securely (the line end regex), you should use the $ anchor.
What is the meaning of $ in regex?
The meaning of $ in regex is the "End of Line" anchor. It asserts that the pattern must appear at the very end of the string (or the end of a line, if multiline mode is enabled). Conversely, the regex beginning of line is represented by the ^ symbol.
How to use a regex optional character?
To make a character optional, place a question mark in regex (?) immediately after it. For example, the pattern colou?r will successfully match both "color" and "colour", making the "u" a regex optional character.