Regex Tester & Debugger

Test and debug regular expressions with real-time highlighting. Find matches, get explanations, and learn how to use regex effectively.

Regular Expression

//

Match Results:

No text to match

Code Implementation

JavaScript

const regex = new RegExp('your_pattern_here', 'g');
const matches = myString.match(regex);

Python

import re
pattern = r'your_pattern_here'
matches = re.findall(pattern, my_string)

PHP

<?php
$pattern = '/your_pattern_here/m';
preg_match_all($pattern, $text, $matches);
?>

Regex Patterns Library

Common patterns to help you get started. Click any pattern to use it.

Email

Match a valid email address

^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$

URL

Match a URL with optional protocol

^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$

IP Address

Match an IPv4 address

^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$

Phone Number

Match common phone number formats

^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$

Date (YYYY-MM-DD)

Match a date in YYYY-MM-DD format

^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12][0-9]|3[01])$

HTML Tag

Basic HTML tag matcher

<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)

Password Strength

Match a strong password (min 8 chars, uppercase, lowercase, number, special char)

^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$

Username

Match a username (3-16 characters, alphanumeric, underscore, hyphen)

^[a-zA-Z0-9_-]{3,16}$

Hex Color

Match a hex color code

^#?([a-fA-F0-9]{6}|[a-fA-F0-9]{3})$

Credit Card Number

Match major credit card numbers

^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|3[47][0-9]{13}|6(?:011|5[0-9]{2})[0-9]{12})$

Regex Cheatsheet

Character Classes

  • \d - Match a digit
  • \w - Match a word character
  • \s - Match a whitespace character
  • [abc] - Match any character in the set
  • [^abc] - Match any character not in the set

Quantifiers

  • * - Match 0 or more times
  • + - Match 1 or more times
  • ? - Match 0 or 1 time
  • {n} - Match exactly n times
  • {n,} - Match at least n times
  • {n,m} - Match between n and m times

Anchors

  • ^ - Start of string/line
  • $ - End of string/line
  • \b - Word boundary

Flags

  • g - Global search (find all matches)
  • i - Case-insensitive search
  • m - Multi-line mode (^ and $ match line starts/ends)
  • s - Dot (.) matches newlines