PlayTools

JavaScript regex sandbox with live highlights

실시간 매칭 강조 표시. g/i/m 플래그 및 캡처 그룹 지원.

Runs in your browser — nothing you enter is uploaded
Examples:
//

Matches highlighted — 2 matches found

Contact us at hello@example.com or support@tools.io for help.

Match Details

#1hello@example.comidx 14
#2support@tools.ioidx 35

JavaScript regex sandbox with live highlights

Dialect differs from PCRE or POSIX—verify lookbehind support in your target engines. Use flags g/i/m/s deliberately: dotAll (s) changes “.” semantics dramatically.

Redact PII before sharing regex screenshots; logs often contain emails and phone numbers.

How the tester works

Type the pattern without surrounding slashes, toggle flags, and paste the text to search. The pattern runs on your browser’s own JavaScript RegExp engine on every keystroke, so what you see is exactly how the same pattern behaves in JavaScript and TypeScript code.

All matches are listed even if the g flag is off — the tester adds it internally for the list — together with each match’s position and its capture groups in order. Matches are highlighted in the text below. Patterns that can match an empty string, such as a* or \b, are stepped through one position at a time, so they show zero-width matches without freezing the page.

Five presets (email, URL, IPv4, date and hex colour) load a working pattern with sample text — useful starting points to adapt rather than definitive validators.

Worked examples

  • Prices: \$\d+(?:\.\d{2})? on “Coffee $4.50, bagel $3, total $7.50” matches $4.50, $3 and $7.50. The dollar sign and the dot are escaped because both are special characters; (?: … ) groups the cents without capturing them.
  • Dates with groups: (\d{4})-(\d{2})-(\d{2}) on “Due 2026-10-01” gives one match with groups 2026, 10 and 01 — in code, a replacement string such as $3/$2/$1 reorders them to 01/10/2026.
  • Whole words: \bcat\b on “cat concatenate cat.” matches the two standalone words and skips “concatenate”.
  • Log lines: ^ERROR.*$ with the m flag matches every line that starts with ERROR. Without m, ^ and $ only match the start and end of the whole text.
  • Greedy vs lazy: <.+> on “<b>bold</b>” matches the entire string, because .+ grabs as much as it can. <.+?> matches “<b>” and “</b>” separately.

Mistakes that cause most regex bugs

  • Unescaped dots: example.com matches “exampleXcom” too. Write example\.com.
  • Missing anchors when validating: \d{5} finds five digits inside “123456789”. For a whole-input check use ^\d{5}$.
  • Catastrophic backtracking: nested quantifiers such as (a+)+$ take exponential time on input like “aaaaaaaaaaaaaaaaaaaaaaaa!”. In a browser that freezes the tab — here as well as in production. Rewrite with a single quantifier — a+$ instead of (a+)+$ — or a more specific character class.
  • Expecting regex to fully validate emails or parse HTML: the email preset accepts typical addresses, not every address RFC 5322 allows, and nested HTML needs a real parser.
  • Forgetting flags: case-sensitive matching is the default — add i if “Error” and “ERROR” should both match.

Moving a pattern to another language

Most everyday syntax — character classes, quantifiers, groups, anchors, lookahead — is identical across JavaScript, Python, Java, C#, PHP and Go. The differences that bite are mostly about escaping and a few advanced features:

  • String escaping: in Java and C# source code every backslash is doubled (“\\d+”); in Python use a raw string, r"\d+".
  • Named groups: JavaScript, .NET and Java write (?<year>\d{4}); Python writes (?P<year>\d{4}).
  • Go (RE2) has no lookahead, lookbehind or backreferences, by design, in exchange for guaranteed linear-time matching.
  • PHP’s preg_ functions need delimiters around the pattern, for example /\d+/i.
  • Lookbehind (?<=…) works in all current browsers and Node.js, but very old browsers lack it.

Privacy

Patterns and test text are processed only in your browser. Log excerpts often contain email addresses, IP addresses and tokens; you can test against them here without them leaving your machine, but scrub them before sharing a screenshot.

In-depth guides

These free tools pair well with this page — open them in a new tab to finish your workflow.

자주 묻는 질문

이 도구는 어떤 정규식 엔진을 사용하나요?

브라우저에 내장된 JavaScript RegExp 엔진을 사용합니다. JavaScript 정규식은 문자 클래스, 수량자, 전방 탐색, 그룹, 역참조 등 대부분의 일반적인 기능을 지원합니다. PCRE에 있는 가변 길이 후방 탐색이나 원자 그룹 같은 일부 기능은 지원하지 않습니다.

정규식 플래그의 의미는 무엇인가요?

주요 플래그: g(전역—첫 번째만이 아닌 모든 일치 찾기), i(대소문자 구분 없음), m(다중행—^와 $가 각 행의 시작/끝에 일치), s(dotAll—.이 개행 문자에도 일치), u(유니코드—완전한 유니코드 지원 활성화).

리터럴 점이나 특수 문자를 매칭하는 방법은?

백슬래시로 이스케이프합니다. 정규식에서 점(.)은 임의의 문자에 일치합니다. 리터럴 점을 매칭하려면 \.로 씁니다. 마찬가지로 \, (, ), [, ], {, }, *, +, ?, ^, $, |는 각 문자 앞에 백슬래시를 붙입니다.

캡처 그룹과 비캡처 그룹의 차이는 무엇인가요?

캡처 그룹(괄호: ())은 일치한 텍스트를 캡처하여 $1, $2 등으로 참조할 수 있게 합니다. 비캡처 그룹(?:...)은 캡처하지 않고 그룹화합니다. 내용을 캡처하지 않고 수량자를 적용하고 싶을 때 유용합니다.

전방 탐색과 후방 탐색이란 무엇인가요?

전방 탐색(?=...)은 현재 위치 뒤에 패턴이 와야 한다고 단언하며 문자를 소비하지 않습니다. 후방 탐색(?<=...)은 앞에 패턴이 있어야 한다고 단언합니다. 예: \d+(?= dollars)는 ' dollars' 앞의 숫자에 일치하지만 ' dollars'는 일치 결과에 포함되지 않습니다.