Regex Tester

Test, validate, and debug regular expressions instantly with real-time match highlighting.

Regular Expression

//

Supported JavaScript flags include g, i, m, s, u, y, and d. Invalid flags or syntax are reported without crashing the tester.

Regex pattern library

Tested JavaScript regex examples with matching and non-matching inputs.

32 of 32 patterns

Email address

Validation
/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/

Checks for a practical email shape with one @ and a dot in the domain.

Examples and limitations

Matches: dev@example.com

Does not match: dev@example

Limitations: This is intentionally pragmatic, not a complete RFC email parser; it does not verify that the address exists.

HTTP or HTTPS URL

Validation
/^https?:\/\/[^\s]+$/i

Requires an HTTP or HTTPS scheme followed by at least one non-space character.

Examples and limitations

Matches: https://example.com/docs?q=1

Does not match: example.com/docs

Limitations: It does not validate every URL rule or confirm that the host is reachable.

IPv4 address

Networking
/^(?:(?:25[0-5]|2[0-4]\d|1?\d?\d)\.){3}(?:25[0-5]|2[0-4]\d|1?\d?\d)$/

Validates four decimal octets, each in the range 0–255.

Examples and limitations

Matches: 192.168.1.10

Does not match: 192.168.1.300

Limitations: It does not distinguish private, loopback, multicast, or reserved address ranges.

Basic IPv6 address

Networking
/^(?:[0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4}$/

Matches the fully expanded eight-group IPv6 notation.

Examples and limitations

Matches: 2001:0db8:0000:0000:0000:ff00:0042:8329

Does not match: 2001:db8::1

Limitations: This educational pattern does not support compressed (::), IPv4-mapped, or zone-indexed IPv6 forms.

UUID v4

Identifiers
/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i

Checks the UUID layout plus the version 4 and RFC variant bits.

Examples and limitations

Matches: 550e8400-e29b-41d4-a716-446655440000

Does not match: 550e8400-e29b-11d4-a716-446655440000

Limitations: It validates format and bits only; it cannot prove uniqueness or how the UUID was generated.

Hexadecimal color

Validation
/^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i

Accepts CSS-style three- or six-digit hexadecimal colors with a leading #.

Examples and limitations

Matches: #0ea5e9

Does not match: 0ea5e9

Limitations: It excludes alpha forms such as #RRGGBBAA and functional color notation.

ISO calendar date

Dates and times
/^\d{4}-\d{2}-\d{2}$/

Checks the YYYY-MM-DD shape used by ISO-style dates.

Examples and limitations

Matches: 2026-10-11

Does not match: 11/10/2026

Limitations: It checks shape, not calendar validity; values such as 2026-99-99 still match.

24-hour time

Dates and times
/^(?:[01]\d|2[0-3]):[0-5]\d$/

Matches hours from 00–23 and minutes from 00–59 in HH:MM format.

Examples and limitations

Matches: 23:45

Does not match: 24:00

Limitations: Seconds, time zones, and leap seconds are not included.

Signed integer

Validation
/^[+-]?\d+$/

Accepts an optional sign followed by one or more decimal digits.

Examples and limitations

Matches: -42

Does not match: 3.14

Limitations: It does not enforce a numeric range and accepts leading zeroes.

Decimal number

Validation
/^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/

Matches signed whole numbers and decimal values such as 12.5 or .5.

Examples and limitations

Matches: -12.50

Does not match: 1,000.00

Limitations: Scientific notation, locale separators, and numeric range are not supported.

Lowercase URL slug

Validation
/^[a-z0-9]+(?:-[a-z0-9]+)*$/

Allows lowercase words or numbers separated by single hyphens.

Examples and limitations

Matches: regex-cheat-sheet

Does not match: Regex Cheat Sheet

Limitations: Whether a slug is unique or appropriate for a specific route must be checked separately.

ASCII alphanumeric string

Validation
/^[A-Za-z0-9]+$/

Requires one or more ASCII letters or digits and no punctuation or spaces.

Examples and limitations

Matches: Build2026

Does not match: Build-2026

Limitations: Unicode letters and underscores are intentionally excluded.

Whitespace run

Text processing
/\s+/g

Finds one or more whitespace characters, including spaces, tabs, and line breaks.

Examples and limitations

Matches: hello world

Does not match: helloworld

Limitations: Whitespace semantics vary by engine and flags; this targets JavaScript behavior.

Duplicate spaces

Text processing
/ {2,}/g

Finds two or more literal consecutive spaces for cleanup.

Examples and limitations

Matches: Too many spaces

Does not match: One space

Limitations: It does not match tabs or newlines; use \s{2,} when those should count.

HTML-like tag

Text processing
/<\/?[A-Za-z][^>]*>/g

Finds text shaped like an opening or closing HTML tag.

Examples and limitations

Matches: <section class="hero">

Does not match: 2 < 3

Limitations: Do not use regex as an HTML parser; nested structure, quoted > characters, and malformed markup need a parser.

JavaScript-style identifier

Programming
/^[A-Za-z_$][A-Za-z0-9_$]*$/

Checks the common ASCII shape of a JavaScript identifier.

Examples and limitations

Matches: user_$1

Does not match: 1stUser

Limitations: It does not reject reserved words and does not cover all Unicode identifier rules.

Double-quoted string

Text processing
/"(?:\\.|[^"\\])*"/g

Finds double-quoted strings while allowing escaped characters inside them.

Examples and limitations

Matches: "hello \"world\""

Does not match: 'hello'

Limitations: It is not a full language lexer and may not handle every multiline or templating syntax.

Common log level

Programming
/\b(?:TRACE|DEBUG|INFO|WARN|ERROR|FATAL)\b/gi

Finds common severity labels in application logs.

Examples and limitations

Matches: 2026-10-11 INFO Request complete

Does not match: NOTICE Request complete

Limitations: Log formats and level names differ between systems.

Common access-log line

Programming
/^\S+ \S+ \S+ \[[^\]]+\] "(?:[^"\\]|\\.)*" \d{3} \d+(?: "[^"]*" "[^"]*")?$/

Matches the broad shape of a Common Log Format or combined access-log line.

Examples and limitations

Matches: 127.0.0.1 - - [11/Oct/2026:10:20:30 +0000] "GET / HTTP/1.1" 200 1234

Does not match: GET / returned okay

Limitations: It checks line shape, not whether methods, dates, status codes, or quoted fields are semantically valid.

Semantic version

Programming
/^v?(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?(?:\+[0-9A-Za-z-]+(?:\.[0-9A-Za-z-]+)*)?$/

Matches the core and optional prerelease/build portions of Semantic Versioning 2.0.

Examples and limitations

Matches: v1.4.0-beta.2

Does not match: 1.4

Limitations: It does not compare versions or enforce project-specific release rules.

MAC address

Networking
/^(?:[0-9A-Fa-f]{2}[:-]){5}[0-9A-Fa-f]{2}$/

Accepts six hexadecimal octets separated by colons or hyphens.

Examples and limitations

Matches: 00:1A:2B:3C:4D:5E

Does not match: 00:1A:2B:3C:4D

Limitations: It does not identify vendor prefixes or guarantee that the address is assigned to a device.

Hostname

Networking
/^(?=.{1,253}$)(?:[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?\.)*[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?$/

Checks labels, hyphen placement, and the maximum hostname length.

Examples and limitations

Matches: api.example.com

Does not match: -api.example.com

Limitations: It does not validate DNS resolution, IDN display names, or every application-specific host rule.

TCP or UDP port

Networking
/^(?:\d|[1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/

Matches an integer from 0 through 65535.

Examples and limitations

Matches: 443

Does not match: 70000

Limitations: It does not show whether a port is open or assigned to a particular service.

Absolute Unix path

Programming
/^\/(?:[^\0\n\/]+\/)*[^\0\n\/]*$/

Checks a slash-prefixed path without null bytes or newline characters.

Examples and limitations

Matches: /var/log/app.log

Does not match: var/log/app.log

Limitations: Filesystem rules differ by operating system, permissions, and normalization requirements.

JSON string token

Programming
/"(?:\\(?:["\\\/bfnrt]|u[0-9A-Fa-f]{4})|[^"\\\u0000-\u001F])*"/

Matches a JSON string token with valid escape forms and no raw control characters.

Examples and limitations

Matches: "line\nvalue"

Does not match: "unescaped line"

Limitations: A token match does not validate a complete JSON document; use a JSON parser for that.

Base64 string

Programming
/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/

Checks the standard padded Base64 alphabet and grouping.

Examples and limitations

Matches: SGVsbG8=

Does not match: SGVsbG8!

Limitations: It does not decode the value or distinguish arbitrary binary data from text.

Hexadecimal number

Programming
/^(?:0x)?[0-9A-Fa-f]+$/i

Accepts hexadecimal digits with an optional 0x prefix.

Examples and limitations

Matches: 0xFF00AA

Does not match: 0xGHI

Limitations: It does not enforce a numeric width or range.

US phone number

Validation
/^(?:\+1[ .-]?)?(?:\(?[2-9]\d{2}\)?[ .-]?)?[2-9]\d{2}[ .-]?\d{4}$/

Accepts common North American phone formats with an optional country code.

Examples and limitations

Matches: +1 (415) 555-0132

Does not match: 123-45-6789

Limitations: Phone numbering plans are complex; this does not verify assignment or support every international format.

US ZIP code

Validation
/^\d{5}(?:-\d{4})?$/

Matches five-digit ZIP codes and optional four-digit extensions.

Examples and limitations

Matches: 94105-1234

Does not match: 9410

Limitations: It checks format only and does not confirm that the ZIP code exists.

ISO date-time prefix

Dates and times
/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$/

Matches an ISO-like date-time with seconds and an explicit UTC offset.

Examples and limitations

Matches: 2026-10-11T14:30:00Z

Does not match: 2026/10/11 14:30:00

Limitations: Calendar validity and leap seconds are not checked.

Simple duration

Dates and times
/^(?:\d+(?:\.\d+)?)(?:ms|s|m|h|d)$/i

Matches a positive numeric duration with a common unit.

Examples and limitations

Matches: 2.5h

Does not match: two hours

Limitations: It does not convert units or accept compound durations such as 1h 30m.

Quoted CSV field

Text processing
/^"(?:""|[^"])*"$/

Validates one quoted CSV field and permits doubled double-quotes inside it.

Examples and limitations

Matches: "two, too"

Does not match: "unterminated

Limitations: CSV dialects vary; this checks one quoted field only and does not parse a complete row.

Test String
Match Result2 matches
Hello 123 World!

Features

  • Match Highlighting: See exactly what your Regular Expression matches in real-time with visual highlighting inside your test string.
  • Replace Testing: Instantly preview how a substitution string (like $1) alters your text based on matched groups.
  • Pattern Library: Search and filter 30+ tested JavaScript regex patterns for validation, networking, dates, programming, identifiers, and text processing.
  • Flag Toggles: Easily swap between global (g), case-insensitive (i), and multiline (m) matching.
  • Zero Latency & Complete Privacy: Runs natively in your browser using JavaScript's RegExp engine — no server uploads, instant feedback.

How it works

A Regular Expression (Regex) is a sequence of characters that specifies a search pattern. They are widely used for string parsing, input validation, data extraction, and search-and-replace workflows. This regex tester includes a searchable library of practical JavaScript regex patterns. For syntax details and edge cases, explore our Regex Cheat Sheet & Common Patterns.

To use this tester:

  1. Enter your pattern in the Regular Expression field (omit surrounding delimiters like /, as they are handled automatically).
  2. Specify your desired flags in the right box (e.g. g for global, i for case-insensitive).
  3. Type or paste your sample text into the Test String pane. Matching text is highlighted automatically with a live match count.
  4. Switch to the Replace tab to preview substitutions using literal strings or group tokens like $1 and $2.

A safe workflow for testing patterns

Use the tester to build a pattern from a small set of representative inputs, then compare matches and replacement output before adding it to application code. For example, test both valid and invalid route IDs rather than checking only one successful sample.

Limit: A regex usually checks syntax or shape, not business meaning. Keep patterns bounded and review nested quantifiers because some expressions can cause excessive backtracking in a production engine.

JavaScript Regex Syntax Reference

A quick reference of common tokens, anchors, and quantifiers supported by the JavaScript RegExp engine.

Character Classes

  • . — Any character except newline
  • \d — Any digit [0-9]
  • \D — Any non-digit
  • \w — Word character [a-zA-Z0-9_]
  • \W — Non-word character
  • \s — Whitespace (space, tab, newline)
  • [abc] — Any character in set
  • [^abc] — Any character NOT in set

Quantifiers & Anchors

  • ^ — Start of string / line
  • $ — End of string / line
  • \b — Word boundary
  • * — 0 or more occurrences
  • + — 1 or more occurrences
  • ? — 0 or 1 occurrence (optional)
  • {n} — Exactly n occurrences
  • {min,max} — Between min and max

Flags & Groups

  • g — Global match (all matches)
  • i — Case-insensitive matching
  • m — Multiline (^ and $ match lines)
  • s — Dot matches newline (dotAll)
  • (abc) — Capturing group
  • (?:abc) — Non-capturing group
  • a|b — Alternation (match a or b)

Common Regex Pitfalls to Avoid

Forgetting to Escape Dots in URLs / Domains

In regex, a period . matches any character. To match a literal dot (such as in example.com), always escape it as example\.com.

Missing Start and End Anchors

When validating entire inputs (like emails or IDs), omitting ^ and $ allows unexpected substrings before or after the valid pattern to pass.

Unintended Greedy Matching

Expressions like <.*> will match from the first < to the last > in an entire file. Use lazy matching <.*?> instead.

Catastrophic Backtracking (ReDoS)

Nested quantifiers like (a+)+$ cause exponential evaluation times on non-matching inputs. Keep quantifier nesting minimal and specific.

Frequently Asked Questions

Which Regex Engine does this tool use?

This tool uses the native JavaScript RegExp engine running directly inside your browser. It reflects the exact behavior of regular expressions executed in Node.js, Next.js, and modern browser applications.

Why doesn't my pattern match all occurrences in the text?

Without the global flag (g), a regular expression stops searching after identifying the very first match. Adding the 'g' flag tells the engine to find all matches throughout the entire input string.

How do capture groups and substitutions work in the Replace tab?

Capture groups are defined with parentheses, like (\w+). In the Replace tab, you can reference these groups using $1 for the first group, $2 for the second group, and $& for the entire match.

What is the difference between greedy and lazy matching?

By default, quantifiers like *, +, and {n,} are greedy — they match as much text as possible. Adding a question mark (like *? or +?) makes them lazy, matching only the shortest string necessary to satisfy the pattern.

How do I match special characters like dots or brackets literally?

Characters with special syntactic meaning in regex — such as . * + ? ^ $ { } ( ) [ ] | \ / — must be escaped with a preceding backslash (\) to match their literal character (e.g., \. to match a literal period).

Is my test string or regular expression sent to a server?

No. DevToolkit runs 100% client-side in your browser. Your expressions, input text, and replacement results never leave your computer.