Open links in new tab
    • Work Report
    • Email
    • Rewrite
    • Speech
    • Title Generator
    • Smart Reply
    • Poem
    • Essay
    • Joke
    • Instagram Post
    • X Post
    • Facebook Post
    • Story
    • Cover Letter
    • Resume
    • Job Description
    • Recommendation Letter
    • Resignation Letter
    • Invitation Letter
    • Greeting Message
    • Try more templates
  1. Regular expressions (regex) in JavaScript are patterns used to match character combinations in strings. They are implemented using the RegExp object or regex literals.

    Example: Basic Usage

    // Match all occurrences of "cat" (case-insensitive)
    const regex = /cat/gi;
    const text = "Cat, caterpillar, and category.";
    const matches = text.match(regex);
    console.log(matches); // Output: ["Cat", "cat", "cat"]
    Copied!

    Creating Regular Expressions

    • Literal Syntax: /pattern/modifiers

    const regex = /hello/i; // Case-insensitive match for "hello"
    Copied!
    • Constructor Syntax: new RegExp("pattern", "modifiers")

    const regex = new RegExp("hello", "i");
    Copied!

    Common Methods

    • test(): Checks if a pattern exists in a string.

    const regex = /world/;
    console.log(regex.test("Hello world")); // true
    Copied!
    • exec(): Returns the first match and its details.

    const regex = /(\d+)/;
    const result = regex.exec("Order #123");
    console.log(result[0]); // "123"
    Copied!
    Feedback
  2. Regular expressions - JavaScript | MDN - MDN Web Docs

    ••
    Regular expressions are patterns used to match character combinations in strings. In …
    Creating a regular expression

    You construct a regular expression in one of two ways:
    •Using a regular expression literal, which consists of a pattern enclosed between slashes, as follows:
    Regular expression literals provide compil…

    Writing a regular expression pattern

    A regular expression pattern is composed of simple characters, such as /abc/, or a combination of simple and special characters, such as /ab*c/ or /Chapter (\d+)\.\d*/. The last example includes parentheses, which are used as a memor…

    Using regular expressions in JavaScript

    Regular expressions are used with the RegExp methods test() and exec() and with the String methods match(), matchAll(), replace(), replaceAll(), search(), and split().
    When you want to know whether a pattern is found in a string, use the test() or searc…

    Examples

    Using special characters to verify input
    In the following example, the user is expected to enter a phone number. When the user presses the "Check" button, the script checks the validity of the number. If the number is valid (matches the characte…

  3. JavaScript Regular Expressions - W3Schools

    Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.

  4. JavaScript RegExp (Regular Expression) - GeeksforGeeks

    Mar 27, 2026 · JavaScript RegExp (Regular Expressions) are patterns used to match, search, and manipulate text in strings. They are widely used for validation, parsing, and text processing tasks in …

  5. Javascript Regex

    In JavaScript, regular expressions are incredibly useful for various tasks such as data validations, search and replace text, and data parsing. This tutorial series helps you master regex in JavaScript from …

  6. JavaScript Regular Expressions: Complete Guide with Examples

    Mar 27, 2026 · Let's demystify regex patterns and show you how to use them effectively in modern applications. Regular expressions (regex) are patterns used to match character combinations in …

  7. JavaScript Regular Expressions Cheat Sheet

    JavaScript regex cheat sheet with pattern syntax, flags, lookaheads, capture groups, common patterns, and practical code examples.

  8. People also ask
    Loading
    Unable to load answer
  9. Regular Expressions (RegEx) in JavaScript – A Handbook for Beginners

    Feb 27, 2024 · You can use regular expressions with various methods available for both the RegExp and String objects in JavaScript. Some methods like test(), exec(), and others have this syntax:

  10. Regular expression syntax cheat sheet - JavaScript | MDN

    24 rows · Mar 17, 2026 · This page provides an overall cheat sheet of all the capabilities of RegExp syntax by aggregating the content of the articles in the RegExp guide. If you need more information on …

  11. Complete Guide to Regular Expressions in JavaScript - Medium

    Oct 28, 2024 · Regular expressions (regex) are a powerful tool in programming, enabling complex text searches and replacements efficiently and succinctly. In JavaScript, regex is extensively used for data...

  12. JavaScript Regex: Syntax, Usage, and Examples - mimo.org

    Learn how to use JavaScript regex for pattern matching, validation, and text manipulation with clear syntax, flags, and practical code examples.