1. Converter Tools > 
  2. Dev Tools > 
  3. Regex Tester

Regex Tester

Test and highlight regex matches, replace text. Supports flags g, i, m, u, s. Copy results. No duplicate flags.

A regular expression (regex) is a pattern that describes text. For example, “one or more digits”, “word boundary”, or “optional prefix”. Use this tool to test a regex against your own text: enter your pattern and optional flags (g, i, m, u, s), then click Test to see matches and highlights, or Replace All to replace matches with your replacement string. Flags are normalized (no duplicate characters). For very long text, consider limiting input to avoid slow backtracking.

Loading…

Advertisement

Examples

  • Pattern (abc)/g on "abc abc" → 2 matches
  • Replace \s+ with space
  • Flags: gi for case-insensitive global match

FAQ

What is a regex?

A regular expression (regex) is a sequence of characters that defines a search pattern. It is used to find, validate, or replace text—for example, to match email addresses, numbers, or specific words. Patterns use special characters (e.g. *, +, ?, \d, []) to mean "zero or more", "one or more", "optional", "digit", or "character class". This tool lets you type a regex and test it against your own text.

What regex flags are supported?

g (global), i (ignore case), m (multiline), u (unicode), s (dotall). Enter them in the Flags field. Duplicates are ignored.

Why do I get 'Invalid flags'?

Only g, i, m, s, u, y are allowed. If you see duplicate flags (e.g. gg), the tool normalizes them automatically.

How do I replace all matches?

Enter your pattern and flags, type the replacement text in the Replacement field, then click Replace All. Use $1, $2 for capture groups.

What are the most common regex character classes?

\d matches a digit (0-9). \w matches a word character (a-z, A-Z, 0-9, _). \s matches whitespace (space, tab, newline). \D, \W, \S match the opposite. [abc] matches a, b, or c. [^abc] matches anything except a, b, c.

What are anchors in regex?

^ matches the start of a string (or line with the m flag). $ matches the end. \b matches a word boundary (between \w and \W). Example: ^hello$ matches only the string 'hello' and nothing else.

What are quantifiers?

* matches 0 or more times. + matches 1 or more. ? matches 0 or 1 (makes the preceding element optional). {n} matches exactly n times. {n,m} matches between n and m times. {n,} matches n or more.

What is the difference between greedy and lazy matching?

Greedy quantifiers (*, +, {n,}) match as much as possible. Lazy quantifiers (*?, +?, {n,}?) match as little as possible. Example: on '', <.*> matches the whole string (greedy), while <.*?> matches '' then '' (lazy).

What are capture groups and how do I reference them?

Parentheses create capture groups: (abc). Group 1 is $1 in replacements and \1 in patterns. (?:abc) is a non-capturing group (useful for grouping without creating a reference). Named groups: (?abc) capture into $.

What is a lookahead and lookbehind?

A lookahead (?=pattern) asserts that what follows matches pattern without consuming it. A negative lookahead (?!pattern) asserts it does not match. Lookbehind (?<=pattern) checks what precedes. Example: \d+(?= dollars) matches numbers followed by ' dollars'.

What is the difference between test() and match() in JavaScript?

regex.test(str) returns true/false — use it when you only need to know if there is a match. str.match(regex) returns an array of matches (or null). With the g flag, match() returns all matches; without it, it returns the first match with capture groups.

What are common regex patterns for validation?

Email (basic): ^[\w.-]+@[\w.-]+\.\w{2,}$. URL: ^https?://[\S]+$. Phone (US): ^\+?1?[-.\s]?\(?\d{3}\)?[-.\s]?\d{3}[-.\s]?\d{4}$. Zip code (US): ^\d{5}(-\d{4})?$. These are simplified — real validation often requires more nuance.

What causes catastrophic backtracking?

Catastrophic backtracking occurs when a regex engine tries exponentially many combinations on a non-matching string. Example: (a+)+ on 'aaaaab'. Avoid nested quantifiers on overlapping patterns. Use atomic groups or possessive quantifiers where supported.

What does the dotall (s) flag do?

By default, the dot (.) matches any character except a newline. With the s (dotall) flag, dot also matches newlines. This is useful for matching HTML tags or multi-line strings that span line boundaries.

Advertisement

Related

  • Base64 Encode and Decode
  • Password Generator
  • QR Code Generator
  • UUID Generator
Ad
Converter Tools

  • Home


    • Conversions
      • Length Converter
      • Area Converter
      • Volume Converter
      • Color Converter
      • Weight Converter
      • Temperature Converter
      • Angle Converter
      • Time Converter
      • Data Size Converter
      • Energy Converter
      • Number Base Converter
    • Calculators
      • Lengths
        • Feet and Inches Calculator
        • Pythagorean Theorem Calculator
        • Circle Circumference Calculator
        • Circle Area Calculator
        • Triangle Area Calculator
        • Rectangle Area and Perimeter Calculator
      • Percentages
        • What is X% of Y Calculator
        • X is What Percent of Y Calculator
        • Percentage Change Calculator
        • Add or Subtract Percentage Calculator
      • Time
        • Age Calculator
        • Date Difference Calculator
        • Day of Week Calculator
        • Countdown Calculator
        • Week Number Calculator
      • Body indices
        • BMR Calculator
        • TDEE Calculator
        • Ideal Weight Calculator
        • Body Fat Percentage Calculator
        • Waist-to-Hip Ratio Calculator
        • Calorie Deficit Calculator
        • BMI Calculator
      • Finance
        • Tip Calculator
        • Discount Calculator
        • Simple Interest Calculator
        • Compound Interest Calculator
        • Loan Payment (EMI) Calculator
      • Math
        • Quadratic Equation Solver
        • Factorial Calculator
        • GCD and LCM Calculator
        • Prime Number Checker
    • Dev Tools
      • Base64 Encode and Decode
      • Password Generator
      • QR Code Generator
      • Regex Tester
      • UUID Generator
    • Images
      • Image Conversions
      • Image Compression
      • Image Resize
      • Image Grayscale
      • EXIF Reader
      • Image Filters
      • Edge Detection
      • Image Crop
      • Image Rotate & Flip
      • Image Format Info
      • Image Thumbnail
    • File conversions
      • CSV and Excel Converter
    • PDF editing
      • Merge PDFs
      • Split PDF
      • Extract PDF pages
      • Rotate PDF pages
      • Add watermark to PDF
      • PDF metadata
    • Cheatsheets
      • CSS
        • CSS Color Cheatsheet
        • CSS Common Properties Cheatsheet
        • CSS Flexbox Cheatsheet
        • CSS Grid Cheatsheet
      • HTML
        • HTML Cheatsheet
      • Markdown
        • Markdown Cheatsheet
      • Git
        • Git Cheatsheet
      • Regex
        • Regex Cheatsheet
      • Time
        • Unix Timestamp Cheat
    • About
    • Contact
    • Privacy Policy
    • Terms of Use

        Built with by Hugo

        We use cookies and similar technologies for ads (e.g. Google AdSense) and analytics. By continuing you consent to our Privacy Policy. You can change preferences anytime.