Regex Tester
Test JavaScript regular expressions online with live match highlighting, capturing groups, named groups, flags and replacement previews directly in your browser.
Test JavaScript Regular Expressions
Enter an ECMAScript regular expression, choose your flags and test it against text instantly in your browser.
Enter only the pattern body. Do not include surrounding slash delimiters.
Match Statistics
A quick overview of the current pattern and results.
Matches
0
Pattern Length
0
Input Length
0
Active Flags
g
Highlighted Matches
Matching portions of the test text are highlighted below.
Match Inspector
Inspect every match, its position and any numbered or named capturing groups.
Replacement Preview
Test how JavaScript's
String.replace()
would transform the input.
JavaScript replacement references such as
$1,
$2
and
$&
can be tested here.
Export Test Results
Copy the pattern, flags, test input and current output.
JavaScript Regex Flags
| Flag | Name | Behaviour |
|---|---|---|
g
|
Global | Continue finding matches throughout the input. |
i
|
Ignore Case | Match without normal case sensitivity. |
m
|
Multiline | Changes how ^ and $ interact with line boundaries. |
s
|
Dot All | Allows . to match line terminators. |
u
|
Unicode | Enables Unicode-aware regex interpretation. |
y
|
Sticky | Requires matching to begin at the current lastIndex position. |
Regex Quick Reference
.
Any character, normally except a line break
\d
Digit
\s
Whitespace
\w
Word-style character
^
Start position
$
End position
*
Zero or more
+
One or more
?
Zero or one / lazy modifier
{n}
Exactly n repetitions
[abc]
One character from the set
(...)
Capturing group
(?:...)
Non-capturing group
(?<name>...)
Named capturing group
\b
Word boundary
JavaScript / ECMAScript Regex Engine
This tester uses the regular-expression engine built into your browser's JavaScript runtime.
JavaScript, PHP PCRE, Python, Java and .NET have similar regex syntax, but they are not completely identical.
Always test an important production pattern in the same runtime where your application will execute it.
Be Careful With Expensive Regular Expressions
Some poorly constructed patterns can perform a very large amount of backtracking, especially against long or attacker-controlled input.
A regex that behaves well with a small test string can still cause performance problems when applied to large production data.
Private Browser-Based Regex Testing
Pattern compilation, matching, highlighting and replacement previews happen directly inside your browser.
- No file upload is required.
- Test text does not need to be sent to SwiftVecto's server.
-
Matching uses the browser's native JavaScript
RegExpimplementation. - Results update automatically as you edit the pattern, flags or test text.
Continue with These Tools
Finished using Regex Tester? Here are some related tools that people commonly use next to complete their workflow faster.
JSON Formatter & Validator
Format, beautify, minify and validate JSON online instantly. Detect invalid JSON, organise nested data and create clean, readable JSON directly in your browser.
JWT Decoder & Inspector
Decode and inspect JSON Web Tokens online. View JWT headers, payloads, claims, timestamps and expiration details instantly in your browser without uploading your token.
Base64 Encoder / Decoder
Encode text to Base64 or decode Base64 back to readable text instantly. Supports UTF-8 and Base64URL with private browser-based processing.
Hash Generator
Generate SHA-1, SHA-256, SHA-384 and SHA-512 hashes instantly from text. Create lowercase or uppercase hexadecimal hashes with private browser-based processing.
UUID Generator
Generate secure random UUID v4 identifiers instantly online. Create single or bulk UUIDs, choose uppercase or lowercase output, remove hyphens and copy or download results directly in your browser.
Password Generator
Generate strong random or memorable passwords instantly. Choose password length, character types, symbols and easy-to-remember word combinations with secure browser-based generation.
URL Encoder / Decoder
Encode or decode URLs and URL components instantly. Convert special characters to percent-encoded values, decode encoded text and work with URI components or form-style query data directly in your browser.
How to Test JavaScript Regular Expressions
Use the SwiftVecto Regex Tester to test JavaScript regular expressions against sample text, inspect matches and capture groups, experiment with flags and preview regex replacements instantly in your browser.
Overview
Regular expressions, commonly called regex, provide a compact language for searching, matching, extracting and replacing patterns in text. They are widely used in JavaScript, PHP, Laravel, web applications, validation logic, log processing, text transformation and many other development workflows. Although different programming languages often use similar regex syntax, their regular-expression engines are not completely identical. This tool is designed primarily around JavaScript and ECMAScript regular expressions because the interactive matching engine runs directly inside the browser. It can help developers experiment with patterns, inspect match positions, understand capture groups and test replacement expressions without repeatedly modifying application code.
Benefits
How It Works
Enter a regular expression pattern without surrounding slash delimiters.
Choose the JavaScript regex flags you want to enable.
Enter or paste text into the test area.
The browser attempts to construct a JavaScript RegExp object using the pattern and selected flags.
If the pattern contains invalid JavaScript regex syntax, the tool displays an error instead of attempting a match.
When the expression is valid, the selected pattern is evaluated against the test text.
Matching portions of text can be highlighted visually.
Each match can be listed with its matched value and starting position.
Capturing groups can be displayed beneath the match that produced them.
Named capturing groups can be shown by their declared group names.
Replacement mode applies the expression and replacement string to create a preview of the transformed text.
All normal interactive testing is performed using the browser JavaScript regex engine.
How to Use This Tool
-
1Enter your regex pattern in the Pattern field.
-
2Do not include the opening and closing slash characters unless you actually want to match literal slashes.
-
3Enable the flags required by your pattern.
-
4Paste or type the text you want to test.
-
5Select Test Regex or allow the interface to refresh the results.
-
6Review the highlighted matches.
-
7Inspect the match count and match positions.
-
8Expand individual results to inspect numbered or named capturing groups.
-
9Enter replacement text if you want to test a find-and-replace operation.
-
10Review the replacement preview before using the pattern in your application.
-
11Use Clear to reset the tester and begin with another expression.
Helpful Tips
- Enter only the regex pattern itself. For example, use \d+ rather than /\d+/ when the interface provides flags separately.
- Enable the global g flag when you want to find every match instead of only the first match.
- Enable i when uppercase and lowercase characters should be treated equivalently.
- Use m when ^ and $ should operate around line boundaries in multiline text.
- Use s when a dot should also match newline characters.
- Use u for Unicode-aware JavaScript regular-expression behaviour where required.
- Escape characters that have special regex meaning when you want to match them literally.
- For example, use \. when you want to match a literal period rather than any character.
- Use parentheses to create capturing groups when you need to extract parts of a match.
- Use non-capturing groups such as (?:...) when grouping is required but the captured value is unnecessary.
- Named groups such as (?<year>\d{4}) can make complex patterns easier to understand.
- Be careful with overly broad patterns such as .* because they may match far more text than intended.
- Avoid catastrophic backtracking patterns when processing large or attacker-controlled input.
- A regex that works in JavaScript may require modification in PHP, Python, Java, .NET or another regex engine.
- Treat example email and URL patterns as useful demonstrations rather than complete standards-compliant validators.
Common Uses
Find every number in a block of text.
Extract dates from application logs.
Find email-like strings in sample data.
Check whether a string follows a simple identifier format.
Find hexadecimal colour values in CSS.
Extract named groups from structured text.
Find repeated whitespace before writing cleanup code.
Test case-insensitive keyword matching.
Preview replacement of repeated spaces with one space.
Extract path components from URLs.
Find HTML-like tags while experimenting with text processing.
Test a regular expression before adding it to JavaScript validation logic.
Worked Examples
The following examples demonstrate how this tool can be used in realistic scenarios.
Finding Numbers
Use the pattern \d+ with the global flag against the text "Order 194 costs £27 and contains 3 items." The tester identifies 194, 27 and 3 as separate matches.
Case-Insensitive Matching
Use the pattern swiftvecto with the i flag. The expression can match SwiftVecto, SWIFTVECTO and other capitalization variants because case sensitivity is disabled.
Extracting a Date with Groups
Use the pattern (\d{4})-(\d{2})-(\d{2}) against "2026-08-13". The complete date is the full match, while the year, month and day appear as three separate capturing groups.
Named Capture Groups
Use (?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2}) against an ISO-style date. The tester can display the captured values under the names year, month and day.
Replacement Preview
Use the pattern \s+ with the global flag against text containing repeated spaces and line spacing, then enter a single space as the replacement to preview how the cleaned text would look.
Common Mistakes
Avoid these common mistakes to achieve the most accurate results.
- Including surrounding / characters when the pattern field already treats the value as the regex body.
- Forgetting the global g flag when expecting multiple matches.
- Using a special regex character literally without escaping it.
- Using .* when a narrower pattern would be more accurate.
- Forgetting that . does not normally match line-break characters unless dot-all behaviour is enabled.
- Expecting ^ and $ to match every line without enabling multiline mode.
- Assuming JavaScript and PHP use exactly the same regular-expression syntax.
- Creating a capturing group when a non-capturing group would be clearer.
- Forgetting that capturing-group numbering is affected by earlier capturing parentheses.
- Using an example email regex as proof that every standards-compliant email address will be accepted.
- Trying to parse arbitrary HTML completely with one regular expression.
- Using a regex when a proper parser would be more reliable for structured languages such as JSON or HTML.
- Ignoring regex performance when testing patterns against very large input.
- Using patterns vulnerable to excessive backtracking on untrusted text.
- Assuming a successful match means the matched data is semantically valid for an application.
Glossary
Definitions of the most important terms used by this tool.
Regex
Short for regular expression, a pattern language used to search, match, extract and replace portions of text.
Regular Expression
A sequence of characters describing a text pattern that a regular-expression engine can evaluate.
Pattern
The regex expression describing the text that should be matched.
Match
A portion of the input text that satisfies the regular-expression pattern.
Regex Engine
The software implementation that interprets and executes regular expressions. JavaScript uses the ECMAScript regular-expression specification.
ECMAScript
The standardized language specification underlying JavaScript, including the regular-expression behaviour used by modern browsers.
Flag
An option that modifies how a regular expression behaves, such as global, case-insensitive or multiline matching.
Global Flag (g)
A JavaScript regex flag that searches for subsequent matches rather than stopping after the first match.
Ignore Case Flag (i)
A JavaScript regex flag that performs case-insensitive matching.
Multiline Flag (m)
A JavaScript regex flag that changes how ^ and $ anchors interact with line boundaries.
DotAll Flag (s)
A JavaScript regex flag that allows the dot metacharacter to match line terminator characters.
Unicode Flag (u)
A JavaScript regex flag enabling Unicode-aware interpretation of parts of the regular-expression syntax.
Sticky Flag (y)
A JavaScript regex flag requiring a match to begin exactly at the current lastIndex position.
Capturing Group
A parenthesized portion of a regex whose matched value is retained separately from the complete match.
Named Capturing Group
A capturing group assigned a readable name using syntax such as (?<year>\d{4}).
Non-Capturing Group
A grouped pattern written as (?:...) that affects matching structure without creating an additional captured result.
Character Class
A pattern component describing a set or range of characters, such as [A-Z], [0-9] or [abc].
Quantifier
Regex syntax controlling how many times a preceding element may occur, including *, +, ?, {3} and {2,5}.
Anchor
A regex element that matches a position rather than ordinary text, such as ^ for the beginning and $ for the end.
Escape Character
The backslash character used to give regex characters a special meaning or remove their special meaning when matching literally.
Replacement String
Text used to replace regex matches. JavaScript replacement strings can also reference captured groups.
Backtracking
A regex-engine behaviour where alternative matching paths may be revisited when the current path fails.
Catastrophic Backtracking
A performance problem where certain regex patterns cause extremely large numbers of matching attempts for particular inputs.
Frequently Asked Questions
What is a regex tester?
A regex tester lets you enter a regular expression and sample text so you can see which portions of the text match the pattern before using it in application code.
Which regex engine does this tool use?
The interactive SwiftVecto Regex Tester is designed around the JavaScript ECMAScript regular-expression engine provided by the browser.
Should I include / characters around my regex?
No. When the interface provides the pattern and flags separately, enter only the regex body. For example, enter \d+ rather than /\d+/g, then enable the g flag using the interface.
What does the g flag do?
The global g flag causes JavaScript to continue finding matches throughout the input instead of returning only the first match.
What does the i flag do?
The i flag enables case-insensitive matching so uppercase and lowercase versions of letters can match each other.
What does the m flag do?
The multiline m flag changes the behaviour of ^ and $ so they can match positions around line boundaries rather than only the beginning and end of the complete input.
What does the s flag do?
The dot-all s flag allows the dot metacharacter to match line terminator characters in addition to other characters.
What does the u flag do?
The u flag enables Unicode-aware JavaScript regex behaviour and changes how some pattern constructs are interpreted.
What is a capturing group?
A capturing group is a parenthesized part of the pattern whose matched content is stored separately so it can be inspected or referenced later.
What is a named capturing group?
A named group assigns a readable name to a capture, such as (?<year>\d{4}), allowing the result to be referenced using that name rather than only its numerical position.
What is a non-capturing group?
A non-capturing group uses (?:...) to group parts of a pattern without creating a separate capture result.
What does \d mean in regex?
\d is a shorthand character class commonly used to match decimal digit characters.
What does \s mean in regex?
\s is commonly used to match whitespace characters such as spaces, tabs and line terminators.
What does \w mean in JavaScript regex?
\w is a shorthand character class commonly matching ASCII letters, digits and underscore. Unicode requirements may need more deliberate pattern construction.
What does .* mean?
The dot normally matches a character and * means zero or more repetitions, so .* can consume a broad span of text. It is often useful but can also be too greedy for some tasks.
What is greedy matching?
A greedy quantifier attempts to consume as much input as possible while still allowing the overall expression to match.
What is lazy matching?
A lazy quantifier such as *? or +? attempts to consume as little input as possible while still allowing the expression to succeed.
Can this tool test replacements?
Yes. The planned interface supports a replacement string and replacement preview so you can inspect the result of a JavaScript regex replacement before using it in code.
Can regex validate email addresses?
Regex can be used for practical email-format checks, but complete standards-compliant email validation is complex. Example email patterns should therefore be treated as practical demonstrations rather than universal validators.
Can regex validate URLs?
Simple URL-like patterns can be tested with regex, but complete URL parsing is usually better handled with a dedicated URL parser because valid URL syntax contains many edge cases.
Can regex parse HTML?
Regex can locate simple HTML-like patterns, but arbitrary HTML is a structured language and should generally be processed with an HTML parser rather than relying on one large regular expression.
Why does my regex work in JavaScript but fail in PHP?
JavaScript and PHP use different regular-expression engines. JavaScript follows ECMAScript regex rules, while PHP commonly uses PCRE. Many patterns are portable, but some syntax and behaviours differ.
Does SwiftVecto send my regex or test text to the server?
The interactive Regex Tester is designed to perform normal pattern compilation, matching and replacement directly in your browser.
Is this Regex Tester free?
Yes. SwiftVecto provides this JavaScript regular-expression testing utility for development, debugging and learning purposes.
Things to Know
- The interactive tool uses the JavaScript ECMAScript regular-expression engine.
- Patterns should normally be entered without surrounding slash delimiters.
- The initial interface supports g, i, m, s and u flags, with y available as an advanced option if exposed in the UI.
- JavaScript regex behaviour is not guaranteed to match PHP PCRE, Python, Java, .NET or other engines exactly.
- Capturing groups and named capturing groups are supported when the browser supports the corresponding JavaScript syntax.
- Replacement previews use JavaScript replacement-string behaviour.
- Example patterns are intended for testing and learning rather than universal standards compliance.
- Normal interactive matching is intended to happen entirely inside the browser.
- Very expensive regex patterns can temporarily consume significant browser processing time.
Disclaimer
Regex matches demonstrate that text satisfies the selected pattern; they do not prove that the underlying value is semantically correct or trustworthy.
Patterns developed with this JavaScript tester may require changes before use with another regular-expression engine.
SwiftVecto example regex patterns should not be treated as authoritative standards-compliant validators for complex formats such as email addresses or URLs.
Poorly designed regular expressions can have significant performance costs, especially when applied to large or attacker-controlled input.
Application developers remain responsible for testing regex behaviour against the actual runtime and input conditions used in production.
Official References
The following official resources were used when developing this tool and are useful for further reading.
MDN Web Docs - Regular Expressions
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions
MDN Web Docs - RegExp
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp
ECMAScript Language Specification - RegExp
https://tc39.es/ecma262/#sec-regexp-regular-expression-objects