Cheatsheet

\w Word char
\d Digit
\s Whitespace
. Any char
[abc] One of
[^abc] Not one of

^ Start of line
$ End of line
\b Word boundary

* 0 or more
+ 1 or more
? 0 or 1
{3} Exactly 3
{1,4} Range

(...) Capture
(?:...) Non-capture
(?<n>) Named

Regular Expression Tester

/ /
Match Information
Running...
Tools

 

Place banner or text content here

 

Documentation

Comprehensive Guide to Regex Tester

Welcome to the W3D Network Regex Tester. This tool allows you to write, test, and debug Regular Expressions in real-time. Whether you are validating emails, extracting data, or cleaning up text, this tool provides instant feedback on matches.

1. What is Regex?

Regular Expressions (Regex) are patterns used to match character combinations in strings. They are the "Swiss Army Knife" of text processing, supported by nearly all modern programming languages (JavaScript, Python, Java, Go, etc.).

Regex allows you to define flexible search patterns, such as "find all email addresses" or "find all words that start with 'A' and end with 'Z'".

2. Building Blocks (Cheatsheet)

Here are the most common tokens you will use:

  • . (Dot): Matches any single character (except newlines).
  • \d: Matches any digit (0-9).
  • \w: Matches any word character (alphanumeric + underscore).
  • \s: Matches any whitespace (space, tab, newline).
  • ^ and $: Anchors that match the start and end of a string/line.
  • *, +, ?: Quantifiers. * (0 or more), + (1 or more), ? (0 or 1).
3. Data Privacy & Security

When testing regex against sensitive data (like real user logs or PII), privacy is critical.

  • 100% Client-Side: This tool runs entirely in your browser using JavaScript's native regex engine. No text or patterns are sent to our servers.
  • Performance Safety: Be careful with "Catastrophic Backtracking" on very long strings, as complex regexes can freeze your browser tab. (This is a local issue, not a server vulnerability).
4. Common Regex Errors

Regex can be tricky. Watch out for these pitfalls:

a. Greedy vs. Lazy

By default, quantifiers like .* are separate "greedy"โ€”they match as much as possible.
Example: <div>...</div> matched with <.*> will match the entire string from the first < to the last >.
Fix: Use .*? to make it "lazy" (stop at the first match).

b. Escaping Special Characters

Characters like ., *, +, ?, (, ), [, ], {, }, ^, $, |, and \ have special meanings. If you want to match them literally, you must escape them with a backslash (e.g., \. to match a real dot).

5. Best Practices
  • Be Specific: Instead of .*, try to match exactly what you expect (e.g., \d+ for an ID). This avoids accidental matches and improves performance.
  • Use Groups: Use parentheses (...) to capture parts of the match. For example, (\d{4})-(\d{2}) captures year and month separately.
  • Test Edges: Always test against empty strings, strings without matches, and strings with special characters to ensure robustness.

JavaScript
const re = /ab+c/i;
const match = re.exec('AbbbC');
console.log(match);
Python
import re
m = re.search(r'\bfoo\b', 'foo bar')
if m: print("Match")