DeveloperUtilityTools

Regex Tester

Test and debug regular expressions with real-time match highlighting, capture groups, and comprehensive flag support. All processing happens in your browser for complete privacy.

/
/g
Flags:
Load Common Pattern Examples
0 characters

What are Regular Expressions?

Regular expressions (regex or regexp) are powerful patterns used to match, search, and manipulate text. They provide a concise and flexible way to identify strings of text, such as specific characters, words, or patterns within larger text bodies. Regular expressions are supported in virtually every modern programming language including JavaScript, Python, Java, PHP, Ruby, and many others.

A regex pattern is composed of a sequence of characters that define a search pattern. These patterns can include literal characters (like "cat"), special characters called metacharacters (like . * + ? [ ] ( ) ^ $ | \), and character classes. The true power of regular expressions lies in their ability to express complex matching logic in a compact, declarative syntax.

Originally developed by mathematician Stephen Cole Kleene in the 1950s as a notation for regular languages, regular expressions became widely adopted in Unix tools like grep, sed, and awk in the 1970s. Today, they are an essential tool for developers, data analysts, and anyone working with text processing and validation.

Common Use Cases for Regular Expressions

Form Validation

Validate user input for email addresses, phone numbers, postal codes, credit card numbers, passwords, and other structured data. Regex patterns ensure data follows the expected format before processing or storage.

Text Search & Replace

Find and replace complex patterns in text editors, IDEs, and scripts. Regex enables powerful search-and-replace operations that would be impossible with simple string matching, including capturing and reusing matched groups.

Data Extraction

Extract specific information from logs, documents, or web pages. Parse structured or semi-structured text to pull out URLs, dates, prices, IDs, or any identifiable pattern for further processing or analysis.

URL Routing

Web frameworks use regex patterns to match and extract parameters from URL paths. Express.js, Django, Rails, and other frameworks rely on regex for flexible routing and parameter extraction in web applications.

Log Analysis

Parse server logs, application logs, or system logs to extract error messages, timestamps, IP addresses, user agents, or other relevant information. Regex patterns help identify patterns in large log files for monitoring and debugging.

Syntax Highlighting

Code editors and IDEs use regex to identify keywords, strings, comments, and other language constructs for syntax highlighting. This makes code more readable and helps developers quickly identify different elements.

Understanding Regex Flags

gGlobal Flag

Without the global flag, regex matches only the first occurrence in the string. With the global flag enabled, the regex continues searching and returns all matches throughout the entire string. Essential for find-and-replace operations and comprehensive text analysis.

iCase Insensitive Flag

Makes the pattern matching case-insensitive. For example, the pattern /hello/i will match "hello", "Hello", "HELLO", or any other case variation. Particularly useful when you want to match text regardless of capitalization, such as user input or natural language text.

mMultiline Flag

Changes the behavior of ^ and $ anchors. Without this flag, ^ matches only at the start of the entire string and $ matches only at the end. With the multiline flag, ^ matches at the start of each line and $ matches at the end of each line. Crucial for working with multi-line text or documents.

sDot All Flag

By default, the dot (.) metacharacter matches any character except newline characters (\n). The dotAll flag changes this behavior so that . matches any character including newlines. Useful when you need to match patterns that span multiple lines.

uUnicode Flag

Enables full Unicode support, treating patterns and strings as sequences of Unicode code points rather than code units. This flag is essential when working with Unicode characters outside the Basic Multilingual Plane, emoji, or when you need accurate character class matching for international text.

ySticky Flag

Matches only from the position indicated by the lastIndex property of the regex object. Unlike the global flag which searches from the last match position, the sticky flag requires the match to occur exactly at lastIndex. Used in parsers and tokenizers for sequential matching.

Frequently Asked Questions

What's the difference between . and \. in regex?

The dot (.) is a special metacharacter that matches any single character (except newlines by default). If you want to match a literal period/dot character, you need to escape it with a backslash: \. For example, to match "example.com", use the pattern example\.com instead of example.com which would match "exampleXcom" where X is any character.

How do I match a specific number of characters?

Use curly braces with numbers to specify exact counts or ranges. For example: \d{3} matches exactly 3 digits, \d{3,5} matches 3 to 5 digits, and \d{3,} matches 3 or more digits. This is more precise than using + (one or more) or * (zero or more) quantifiers.

What are capture groups and how do I use them?

Capture groups are portions of a regex pattern enclosed in parentheses ( ) that "capture" the matched text for later use. For example, in the pattern (\d{3})-(\d{4}), the two groups capture the area code and number separately from a phone number like "555-1234". You can reference these groups in replacements using $1, $2, etc., or access them programmatically in your code.

What's the difference between greedy and lazy matching?

By default, quantifiers like *, +, and {n,m} are greedy—they match as much text as possible. For example, .* in the string "<div>content</div>" matches the entire string. Adding a ? after the quantifier makes it lazy: .*? matches as little as possible, so it would match just "<div>" first. Use lazy matching when you want to match the shortest possible string.

How do I match a word boundary?

Use \b to match a position between a word character (\w) and a non-word character, or at the start/end of a string. For example, \bcat\b matches "cat" as a whole word but not "category" or "scat". Word boundaries are essential for matching complete words without accidentally matching parts of longer words.

Can I use regex to match nested structures like HTML?

Regular expressions are fundamentally limited and cannot fully parse nested or recursive structures like HTML, XML, or balanced parentheses. While you can write regex patterns to match simple, non-nested cases, attempting to match properly nested structures will fail or produce incorrect results. For parsing HTML or XML, use dedicated parsing libraries like DOMParser, BeautifulSoup, or xml2js instead.

Why isn't my regex pattern matching Unicode characters?

If you're working with Unicode characters (emoji, accented letters, non-Latin scripts), enable the Unicode flag (u). Without it, character classes like \w or . may not work correctly with Unicode. For example, use /[\u0400-\u04FF]+/u to match Cyrillic characters, or /\p{Emoji}/u to match emoji when supported by your regex engine.

How do I escape special characters in regex?

To match literal special characters like . * + ? ^ $ [ ] { } ( ) | \, you need to escape them with a backslash. For example, to match "example.com", use example\.com. To match a backslash itself, use \\. If you're dynamically building regex patterns from user input, use a function to escape all special characters to prevent regex injection vulnerabilities.

What are lookaheads and lookbehinds?

Lookaheads and lookbehinds are zero-width assertions that check for patterns without including them in the match. Positive lookahead (?=...) ensures a pattern follows, negative lookahead (?!...) ensures it doesn't. For example, \d+(?= dollars) matches numbers followed by " dollars" but doesn't include " dollars" in the match. Lookbehinds work similarly: (?<=...) checks what comes before, (?<!...) checks what doesn't come before.

Is my data safe when using this tool?

Yes, absolutely. All regex testing and matching happens entirely in your browser using JavaScript. No patterns or test strings are ever sent to our servers or any third party. You can even use this tool offline once the page is loaded. Your privacy and data security are completely protected. This tool is safe to use with sensitive data or proprietary patterns.

Basic Regex Syntax Reference

Character Classes

.Any character (except newline)
\dAny digit [0-9]
\wWord character [A-Za-z0-9_]
\sWhitespace character
[abc]Any of a, b, or c
[a-z]Character range a to z

Quantifiers

*Zero or more
+One or more
?Zero or one
{n}Exactly n times
{n,}n or more times
{n,m}Between n and m times

Anchors

^Start of string/line
$End of string/line
\bWord boundary
\BNot word boundary

Groups & Alternation

(abc)Capture group
(?:abc)Non-capturing group
a|bMatch a or b
\1Backreference to group 1

Related Developer Tools

Explore other text processing and validation tools to streamline your development workflow: