Test, debug, and refine your regular expressions in real-time using the Qodex JavaScript Regex Tester. Whether you’re working on email validation, password security, or URL parsing, this tool helps you validate patterns instantly with visual feedback. It supports all standard JavaScript regex syntax and flags.
Need sample data? Use our Email Generator, Password Generator, or UUID Generator to test your expressions thoroughly.
For testing patterns in other languages, explore our Java Regex Tester, Python Regex Tester, or Go Regex Tester.
[A-Z]
: uppercase letters[a-z]
: lowercase letters[0-9]
: digits\.
: a literal dot+
: one or more of the preceding*
: zero or more of the preceding?
: optional (zero or one)^
: start of string$
: end of string
Test your APIs today!
Write in plain English — Qodex turns it into secure, ready-to-run tests.
Regular Expression - Documentation
Javascript Regex Tester
JavaScript’s RegExp object provides a powerful way to perform pattern matching and text manipulation. Regular expressions are essential for tasks like form validation, input sanitization, and dynamic text extraction in web development.
With the Qodex JavaScript Regex Tester, you can:
Write and test regex patterns in real-time.
Visualize matches instantly as you type.
Experiment with flags like i, g, m, u, and y.
Validate patterns for emails, passwords, phone numbers, and more.
Enhance your testing by generating sample data using tools like the Email Generator, Password Generator, or Phone Number Generator.
Core Constructs of JavaScript Regex
JavaScript regex uses a variety of tokens and constructs to match patterns. Here’s a breakdown of the essential building blocks:
Metacharacters
.
: Matches any character except newline characters (\n
). Commonly used as a wildcard.Example:
/a.b/
matches "acb
", "a9b
", but not "ab
".^
: Matches the start of a string or line (depending on the m flag).Example:
/^Hello/
matches "Hello world
" but not "Say Hello
".$
: Matches the end of a string or line (depending on the m flag).Example:
/world$/
matches "Hello world
" but not "world peace
".|
: Acts as an OR operator between two patterns.Example:
/cat|dog/
matches either "cat
" or "dog
".
Character Classes
[abc]
: Matches any single character that isa
,b
, orc
.Example:
/gr[ae]y/
matches both "gray
" and "grey
".[^abc]
: Matches any character excepta
,b
, orc
.Example:
/[^0-9]/
matches any non-digit character.[a-zA-Z]
: Matches any alphabet letter, lowercase or uppercase.Example:
/[A-Z]/
matches uppercase letters only.
Predefined Character Classes
\\d
: Matches any digit character; equivalent to[0-9]
.\\D
: Matches any character that is not a digit.\\s
: Matches any whitespace character (space, tab, newline, etc.).\\S
: Matches any non-whitespace character.\\w
: Matches any word character (letters, digits, and underscores); equivalent to[a-zA-Z0-9_]
.\\W
: Matches any non-word character.
Quantifiers
*
: Matches 0 or more repetitions of the preceding token.Example:
/ab*/
matches "a
", "ab
", "abb
", etc.+
: Matches 1 or more repetitions of the preceding token.Example:
/ab+/
matches "ab
", "abb
", but not "a
".?
: Matches 0 or 1 time; also makes quantifiers lazy when used as a suffix (e.g., *?).Example:
/ab?/
matches "a
" or "ab
".{n}
: Matches exactly n occurrences of the preceding token.Example:
/a{3}/
matches "aaa
".{n,}
: Matches n or more occurrences.Example:
/a{2,}/
matches "aa
", "aaa
", etc.{n,m}
: Matches between n and m occurrences.Example:
/a{2,4}/
matches "aa
", "aaa
", or "aaaa
".
Special Constructs
(abc)
: Capturing group; stores the matched text so it can be reused later using backreferences (\1, etc.).(?:abc)
: Non-capturing group; used when you want to group parts of a pattern but don’t need to capture them.(?=abc)
: Positive lookahead; asserts that what follows the current position is abc.(?!abc)
: Negative lookahead; asserts that what follows is not abc.
Anchors and Boundaries
\b
: Matches a word boundary (between \w and \W).=\B
: Matches a non-word boundary.\A
: Not supported in JavaScript (use ^ for beginning of string).\Z
: Not natively supported (use $ for end of string, accounting for newline when using m flag).
Flags
i
: Case-insensitive match (e.g., /abc/i matches ABC, Abc, etc.).g
: Global search—finds all matches instead of stopping after the first.m
: Multiline mode—makes ^ and $ match at the start/end of lines rather than the whole string.u
: Unicode mode—enables full Unicode support, letting regex process surrogate pairs correctly.y
: Sticky mode—matches only from the current lastIndex of the regex.
JavaScript Regular Expressions Examples
Example 1: Email Validation
Test this pattern with our Email Regex JavaScript Validator.
Example 2: Password Strength Check
Validate your password strength using the Password Regex JavaScript Validator or generate strong passwords with our Password Generator.
Example 3: Extracting Words from a String
Practical Tips for JavaScript Regular Expressions
Use the RegExp constructor for dynamic patterns, but remember to escape backslashes (\\).
Always reset lastIndex when using regex with g or y flags inside loops.
Use (?:...) for non-capturing groups when you’re grouping for logic only.
Use (?=...) and (?!...) to write powerful conditional patterns.
Enable the u flag for full Unicode and emoji support. Try it with the Unicode Validator.
Avoid complex nested groups for performance-critical code.
Break large regex patterns into modular units and test each section using the JavaScript Regex Tester.
Validate with real data using our Email Generator, Phone Number Generator, and Password Generator.
Use the Credit Card Validator or IP Address Validator for field-specific validations.
Common Use Cases
Form Validation: Validate inputs like emails, passwords, and phone numbers.
Search Filters: Build dynamic search functionality using pattern matching.
String Sanitization: Remove or extract unwanted text, special characters, or HTML tags.
Keyword Extraction: Use regex to identify hashtags, mentions, or domains in user-generated content.
Text Parsing: Break down structured strings (like CSV, logs, or configuration values) into usable tokens.
Data Highlighting: Find and style matched segments in a visual interface.
Recommended Tools
Here are additional Qodex tools to support your JavaScript regex development: