Javascript RegEx Tester

Search...

⌘K

Javascript RegEx Tester

Search...

⌘K


Javascript RegEx Tester

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.

contra@qodex.ai
Possible security issues
This regex appears to be safe.
Explanation
  • [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
Match information
Match 1: "contra@qodex.ai" at index 0
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. Whether you’re working on email validation, password security, or URL parsing, this tool helps you validate patterns instantly with visual feedback.


Enhance your testing by generating sample data using tools like the Email Generator, Password Generator, or Phone Number Generator.


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.


For testing patterns in other languages, explore our Java Regex Tester, Python Regex Tester, or Go Regex Tester.


Why Use Regex?


Regular expressions—commonly called regex—are an essential tool for anyone who works with text. They let you search, match, and manipulate strings with precision, whether you’re validating an email address, checking password strength, or extracting data from logs. Regex isn’t just for JavaScript: it’s widely supported in languages like Python, Java, and Go, making it a must-have skill in any developer’s toolkit.


What Makes Regex Powerful?


  • Pattern Matching: Quickly find specific strings or patterns in large texts.

  • Validation: Ensure user input (like emails or phone numbers) is formatted correctly.

  • Data Extraction: Pull out useful info from files, logs, or datasets.

Whether you’re just starting with regex or looking to fine-tune complex expressions, mastering the basics can save you time and frustration across a range of coding projects.


How to Use the JavaScript Regex Tester


  • Enter Your Regex: Start by typing or pasting your regular expression into the designated field.

  • Input Test Strings: Provide a sample string to test your regex against.

  • Analyze Results: Instantly view matches, capture groups, and pattern insights as you type.

  • Adjust and Re-test: Refine your regex based on immediate feedback—experiment, tweak, and perfect your pattern with ease.

This seamless workflow makes it simple to craft complex expressions and see real-time results, helping you master regex faster and with fewer headaches.


Recommended Approach for Mastering Regular Expressions


Learning regular expressions can feel daunting at first, but a step-by-step approach makes it manageable—and even fun. Start with the basics: focus on the core syntax such as character classes, quantifiers, and anchors. Tinker with simple patterns before moving on to more complex constructs.


Make use of interactive regex testers (like the one you’re using here) to instantly see how your patterns behave with real input. These tools are invaluable for debugging and refining your understanding in real time.


As you grow more confident, branch out into advanced techniques—try using lookaheads, non-capturing groups, or exploring Unicode support. Regular expressions are a powerful skillset: treat your learning as an ongoing process, experimenting with different pattern challenges and scenarios you encounter in your projects.


And of course, don’t hesitate to consult documentation, online tutorials, or regex cheat sheets. Every new pattern you write adds to your toolkit, making future tasks quicker and more reliable.



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 is a, b, or c.

    Example: /gr[ae]y/ matches both "gray" and "grey".


  • [^abc] : Matches any character except a, b, or c.

    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

  • () : Capturing group
    Stores the matched text so it can be reused later using backreferences (like \1, \2, etc.).

  • (?:...) : Non-capturing group
    Groups parts of a pattern without capturing them—useful when you want to apply quantifiers or alternation without storing the match.

  • (?=...) : Positive lookahead
    Asserts that what follows the current position matches the pattern inside.

  • (?!...) : Negative lookahead
    Asserts that what follows the current position does not match the pattern inside.


Advanced Techniques


Lookahead and Lookbehind

Lookahead and lookbehind are advanced techniques that let you match a pattern only if it is (or isn’t) followed or preceded by another pattern—without including that surrounding text in the final match.

  • Lookahead: Already shown above, like (positive) and (negative).

    Example: matches only if it is immediately followed by .

  • Lookbehind: Syntax is (positive) and (negative).

    Example: matches only if it is immediately preceded by .

Note: JavaScript supports lookbehind only in modern environments (ES2018+), and not all browsers may support it.

These constructs are especially useful for tricky patterns where you need to assert context without capturing it, like matching a word only when it isn’t part of an email address, or extracting numbers not surrounded by certain symbols.


Non-Capturing Groups:

Use to group parts of your pattern without saving that portion for backreferencing—great for alternation and grouping logic.


Flags Overview:
  • (global): Find all matches, not just the first.

  • (ignore case): Case-insensitive matching.

  • (multiline): and match at line breaks.

  • (unicode): Enables full Unicode support, including emoji and astral symbols.

  • (sticky): Matches only from the regex’s position.


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.


Tips for Writing Effective Regex


  • Start Simple: Build your pattern step by step. Tackle smaller components (like digits, words, or special characters) before combining them into a full expression.

  • Use Online Regex Testers: Tools like this one are invaluable for experimenting with and debugging your expressions. Instantly see matches, errors, and suggestions as you type.

  • Leverage Flags: Don’t forget to use regex flags such as (global), (case-insensitive), and (multiline) to fine-tune how your pattern matches input.

  • Test with Real Data: Whenever possible, try your patterns against realistic sample data—like emails, passwords, or URLs—to catch edge cases early.


With these practices, you’ll write more accurate and efficient regex patterns—and spend less time debugging tricky issues.


JavaScript Regular Expressions Examples


Example 1: Email Validation

Test this pattern with our Email Regex JavaScript Validator.

const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\.[a-zA-Z]{2,}$/;
const email = "user@example.com";
console.log("Email Valid:", emailPattern.test(email));


Example 2: Password Strength Check

Validate your password strength using the Password Regex JavaScript Validator or generate strong passwords with our Password Generator.

const passwordPattern = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/;
const password = "Aa123456!";
console.log("Password Strong:", passwordPattern.test(password));


Example 3: Extracting Words from a String

const text = "Regex is #1 at pattern matching!";
const wordPattern = /\b\w+\b/g;
let match;
while ((match = wordPattern.exec(text)) !== null) {
    console.log("Found:", match[0]);
}


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.


Where to Get Help with Regular Expressions


Still scratching your head over a tricky regex? You’re not alone. If you run into challenges or want to dive deeper, there are plenty of supportive communities and resources to explore:


Stack Overflow: Ask questions or browse solutions from millions of developers worldwide.

MDN Web Docs: The Mozilla Developer Network has a comprehensive guide and reference for JavaScript regular expressions.

Reddit’s r/regex: Engage in regex discussions, get help, and see real-world examples from the community.

Regex101: A live regex editor and debugger with a helpful explanation tool.

MDN Community Forums: Another great place for both beginner and advanced regex users to discuss and troubleshoot.


Whether you’re debugging an expression or building something complex, these resources can help get you unstuck and back to coding with confidence.

Recommended Tools

Here are additional Qodex tools to support your JavaScript regex development:

 

Related Regex Validators


Data Generators


Other Language Regex Testers


Frequently asked questions

How do I create a regex in JavaScript?×
Use literal syntax /pattern/flags or new RegExp("pattern", "flags").
How do I make my regex case-insensitive?+
What does the g flag do in JavaScript regex?+
How can I validate an email using JavaScript regex?+
What tool can I use to test regex patterns easily?+

Javascript RegEx Tester

Search...

⌘K

Javascript RegEx Tester

Search...

⌘K


Javascript RegEx Tester

Javascript RegEx Tester

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.

contra@qodex.ai
Possible security issues
This regex appears to be safe.
Explanation
  • [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
Match information
Match 1: "contra@qodex.ai" at index 0
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. Whether you’re working on email validation, password security, or URL parsing, this tool helps you validate patterns instantly with visual feedback.


Enhance your testing by generating sample data using tools like the Email Generator, Password Generator, or Phone Number Generator.


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.


For testing patterns in other languages, explore our Java Regex Tester, Python Regex Tester, or Go Regex Tester.


Why Use Regex?


Regular expressions—commonly called regex—are an essential tool for anyone who works with text. They let you search, match, and manipulate strings with precision, whether you’re validating an email address, checking password strength, or extracting data from logs. Regex isn’t just for JavaScript: it’s widely supported in languages like Python, Java, and Go, making it a must-have skill in any developer’s toolkit.


What Makes Regex Powerful?


  • Pattern Matching: Quickly find specific strings or patterns in large texts.

  • Validation: Ensure user input (like emails or phone numbers) is formatted correctly.

  • Data Extraction: Pull out useful info from files, logs, or datasets.

Whether you’re just starting with regex or looking to fine-tune complex expressions, mastering the basics can save you time and frustration across a range of coding projects.


How to Use the JavaScript Regex Tester


  • Enter Your Regex: Start by typing or pasting your regular expression into the designated field.

  • Input Test Strings: Provide a sample string to test your regex against.

  • Analyze Results: Instantly view matches, capture groups, and pattern insights as you type.

  • Adjust and Re-test: Refine your regex based on immediate feedback—experiment, tweak, and perfect your pattern with ease.

This seamless workflow makes it simple to craft complex expressions and see real-time results, helping you master regex faster and with fewer headaches.


Recommended Approach for Mastering Regular Expressions


Learning regular expressions can feel daunting at first, but a step-by-step approach makes it manageable—and even fun. Start with the basics: focus on the core syntax such as character classes, quantifiers, and anchors. Tinker with simple patterns before moving on to more complex constructs.


Make use of interactive regex testers (like the one you’re using here) to instantly see how your patterns behave with real input. These tools are invaluable for debugging and refining your understanding in real time.


As you grow more confident, branch out into advanced techniques—try using lookaheads, non-capturing groups, or exploring Unicode support. Regular expressions are a powerful skillset: treat your learning as an ongoing process, experimenting with different pattern challenges and scenarios you encounter in your projects.


And of course, don’t hesitate to consult documentation, online tutorials, or regex cheat sheets. Every new pattern you write adds to your toolkit, making future tasks quicker and more reliable.



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 is a, b, or c.

    Example: /gr[ae]y/ matches both "gray" and "grey".


  • [^abc] : Matches any character except a, b, or c.

    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

  • () : Capturing group
    Stores the matched text so it can be reused later using backreferences (like \1, \2, etc.).

  • (?:...) : Non-capturing group
    Groups parts of a pattern without capturing them—useful when you want to apply quantifiers or alternation without storing the match.

  • (?=...) : Positive lookahead
    Asserts that what follows the current position matches the pattern inside.

  • (?!...) : Negative lookahead
    Asserts that what follows the current position does not match the pattern inside.


Advanced Techniques


Lookahead and Lookbehind

Lookahead and lookbehind are advanced techniques that let you match a pattern only if it is (or isn’t) followed or preceded by another pattern—without including that surrounding text in the final match.

  • Lookahead: Already shown above, like (positive) and (negative).

    Example: matches only if it is immediately followed by .

  • Lookbehind: Syntax is (positive) and (negative).

    Example: matches only if it is immediately preceded by .

Note: JavaScript supports lookbehind only in modern environments (ES2018+), and not all browsers may support it.

These constructs are especially useful for tricky patterns where you need to assert context without capturing it, like matching a word only when it isn’t part of an email address, or extracting numbers not surrounded by certain symbols.


Non-Capturing Groups:

Use to group parts of your pattern without saving that portion for backreferencing—great for alternation and grouping logic.


Flags Overview:
  • (global): Find all matches, not just the first.

  • (ignore case): Case-insensitive matching.

  • (multiline): and match at line breaks.

  • (unicode): Enables full Unicode support, including emoji and astral symbols.

  • (sticky): Matches only from the regex’s position.


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.


Tips for Writing Effective Regex


  • Start Simple: Build your pattern step by step. Tackle smaller components (like digits, words, or special characters) before combining them into a full expression.

  • Use Online Regex Testers: Tools like this one are invaluable for experimenting with and debugging your expressions. Instantly see matches, errors, and suggestions as you type.

  • Leverage Flags: Don’t forget to use regex flags such as (global), (case-insensitive), and (multiline) to fine-tune how your pattern matches input.

  • Test with Real Data: Whenever possible, try your patterns against realistic sample data—like emails, passwords, or URLs—to catch edge cases early.


With these practices, you’ll write more accurate and efficient regex patterns—and spend less time debugging tricky issues.


JavaScript Regular Expressions Examples


Example 1: Email Validation

Test this pattern with our Email Regex JavaScript Validator.

const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\\\.[a-zA-Z]{2,}$/;
const email = "user@example.com";
console.log("Email Valid:", emailPattern.test(email));


Example 2: Password Strength Check

Validate your password strength using the Password Regex JavaScript Validator or generate strong passwords with our Password Generator.

const passwordPattern = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/;
const password = "Aa123456!";
console.log("Password Strong:", passwordPattern.test(password));


Example 3: Extracting Words from a String

const text = "Regex is #1 at pattern matching!";
const wordPattern = /\b\w+\b/g;
let match;
while ((match = wordPattern.exec(text)) !== null) {
    console.log("Found:", match[0]);
}


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.


Where to Get Help with Regular Expressions


Still scratching your head over a tricky regex? You’re not alone. If you run into challenges or want to dive deeper, there are plenty of supportive communities and resources to explore:


Stack Overflow: Ask questions or browse solutions from millions of developers worldwide.

MDN Web Docs: The Mozilla Developer Network has a comprehensive guide and reference for JavaScript regular expressions.

Reddit’s r/regex: Engage in regex discussions, get help, and see real-world examples from the community.

Regex101: A live regex editor and debugger with a helpful explanation tool.

MDN Community Forums: Another great place for both beginner and advanced regex users to discuss and troubleshoot.


Whether you’re debugging an expression or building something complex, these resources can help get you unstuck and back to coding with confidence.

Recommended Tools

Here are additional Qodex tools to support your JavaScript regex development:

 

Related Regex Validators


Data Generators


Other Language Regex Testers


Frequently asked questions

How do I create a regex in JavaScript?×
Use literal syntax /pattern/flags or new RegExp("pattern", "flags").
How do I make my regex case-insensitive?+
What does the g flag do in JavaScript regex?+
How can I validate an email using JavaScript regex?+
What tool can I use to test regex patterns easily?+