Regex Tester
Test regular expressions with real-time matching and highlighting. Supports JavaScript regex flags (g, i, m, s). See match groups, captures, and indices. Free online regex tester.
Enter a regex pattern and test string above — results update live
About Regular Expressions
Regular expressions (regex or regexp) are sequences of characters that define search patterns. They are one of the most powerful tools in a developer's toolkit, used for matching, extracting, and manipulating text across virtually every programming language — JavaScript, Python, Java, Go, PHP, Ruby, and more. Whether you're validating user input, parsing log files, extracting data from HTML, or performing complex find-and-replace operations, regex provides a concise and flexible syntax to describe exactly what you're looking for.
A regular expression engine works by compiling your pattern into a state machine that processes the input string character by character. When the engine finds a sequence of characters that satisfies the pattern, it reports a match. Modern regex engines support features like lookaheads, lookbehinds, non-greedy quantifiers, and named capture groups — making it possible to express remarkably complex matching logic in a single line.
This online regex tester uses JavaScript's built-in RegExp engine, which means your patterns will behave exactly as they would in any browser or Node.js environment. The tool highlights matches in real time as you type, shows capture groups and their indices, and supports all JavaScript regex flags. It's ideal for prototyping patterns before embedding them in your code, debugging why a pattern isn't matching what you expect, or learning regex syntax interactively.
Developers frequently use regex alongside other tools in their workflow. For example, you might use a regex to extract Unix timestamps from log files, validate that a string is a properly formatted UUID, or parse the payload of a JSON Web Token. Understanding regex is a foundational skill that pays dividends across every area of software development.
JavaScript Regex Flags
g— Global: find all matches, not just the firsti— Case-insensitive matchingm— Multiline:^and$match line boundariess— Dotall:.matches newline charactersu— Unicode: treat pattern as Unicode code pointsy— Sticky: match from lastIndex position only
Practical Regex Examples
1. Validate an email address:
^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$This pattern checks for a standard email format: one or more valid characters before the @, a domain name, and a top-level domain of at least two characters. While not RFC 5322 compliant, it covers the vast majority of real-world email addresses.
2. Extract IPv4 addresses from text:
\b(\d{1,3}\.){3}\d{1,3}\bMatches patterns like 192.168.1.1 or 10.0.0.255. The \b word boundaries prevent matching partial numbers embedded in longer strings. Useful when parsing network logs or configuration files — pairs well with our Subnet Calculator for network planning.
3. Match a UUID v4 format:
[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}This pattern specifically matches UUID version 4 strings, checking that the version nibble is 4 and the variant bits are correct. Use the i flag for case-insensitive matching.
4. Parse a date in YYYY-MM-DD format:
(\d{4})-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])Captures year, month, and day as separate groups. The month is restricted to 01-12 and the day to 01-31. Each group can be accessed individually in your code for further processing.
5. Find all URLs in a block of text:
https?://[^\s<>"{}|\\^`\[\]]+Matches HTTP and HTTPS URLs by starting at the protocol and consuming everything that isn't whitespace or a character that typically terminates a URL in context. Useful for link extraction from documents or chat logs.
Character Classes Quick Reference
\d— Digit [0-9]\D— Non-digit\w— Word character [a-zA-Z0-9_]\W— Non-word character\s— Whitespace (space, tab, newline)\S— Non-whitespace.— Any character (except newline by default)\b— Word boundary (zero-width)
Quantifiers
*— Zero or more (greedy)+— One or more (greedy)?— Zero or one (optional){n}— Exactly n times{n,m}— Between n and m times*?,+?— Non-greedy (lazy) versions
Frequently Asked Questions
What is the difference between greedy and lazy regex matching?
Greedy quantifiers (*, +, {n,m}) match as many characters as possible while still allowing the overall pattern to succeed. Lazy quantifiers (*?, +?, {n,m}?) match as few characters as possible. For example, given the string "<b>hello</b>", the greedy pattern <.+> matches the entire string, while the lazy pattern <.+?> matches only "<b>". Use lazy matching when you want the shortest possible match.
How do I match a literal dot or special character in regex?
Special characters like . * + ? ^ $ { } [ ] ( ) | \ have special meaning in regex. To match them literally, escape them with a backslash. For example, use \. to match a period, \$ to match a dollar sign, or \[ to match a literal bracket. Inside a character class [...], most special characters lose their meaning except for ] \ ^ and -.
What are capture groups and how do I use them?
Capture groups are created by wrapping part of your pattern in parentheses (). They serve two purposes: grouping (to apply quantifiers to a sub-expression) and capturing (to extract the matched text). In JavaScript, captured groups are accessible via match[1], match[2], etc. Named groups use the syntax (?<name>...) and can be accessed via match.groups.name. Non-capturing groups (?:...) group without capturing, which is slightly more efficient when you don't need the matched text.
Why does my regex work in one language but not another?
Regex flavors differ between languages. JavaScript doesn't support lookbehinds with variable length (though modern engines are adding support), POSIX regex lacks lookaheads entirely, and Python's re module has different Unicode handling than JavaScript. Features like atomic groups, possessive quantifiers, and conditional patterns are available in some engines (PCRE, .NET) but not others. Always test your regex in the target language's engine. This tool uses JavaScript's RegExp, which matches browser and Node.js behavior.
Is this regex tester safe to use with sensitive data?
Yes. This regex tester runs entirely in your browser using JavaScript. No data is transmitted to any server — your patterns and test strings never leave your machine. You can verify this by checking the network tab in your browser's developer tools while using the tool.
Related Tools
- JSON Formatter — Format and validate JSON data
- Base64 Encoder/Decoder — Encode or decode Base64 strings
- JWT Decoder — Decode and inspect JSON Web Tokens
- Password Generator — Generate secure random passwords