Regex Tester

Test regex patterns in real time with match highlighting and replacement.

๐Ÿ“– How to Use

1
Enter Pattern

Type the regex pattern to test. e.g. \d+, [a-z]+

2
Enter Test String

Type the string to apply the pattern to. Matches are highlighted in real time.

3
Replace (Optional)

Enter a replacement string and click ๐Ÿ”„ Replace to see the substituted result.

๐Ÿ’ก Tip: g flag = global search, i = case-insensitive, m = multiline mode.

About the Regex Tester

A regular expression is a compact pattern language for matching, extracting, and replacing text. In JavaScript it lives on the RegExp object and powers everything from form validation and route matching to log scraping. This tester compiles your pattern against a sample string in real time, highlights every match, and lets you run a substitution — all in the browser, so patterns and input never leave your machine.

How it works

A pattern can be written two ways. A regex literal such as /\d+/g is delimited by forward slashes and compiled when the script loads. The constructor form new RegExp("\\d+", "g") takes a runtime string, which is essential when the pattern is assembled from variables — but you must double the backslashes because the string layer consumes one. After the closing slash (or as the second constructor argument) come flags: g for global (every match, not just the first), i for case-insensitive, m for multiline (^ and $ match line boundaries), s for dotAll (the dot matches newlines), u for full Unicode handling, and y for sticky (match anchored at lastIndex).

Several methods consume a compiled pattern: test() returns a boolean, exec() returns one match object with capture groups, String.match() returns the first match (or all matches with the g flag), String.matchAll() iterates every match with its groups, and String.replace() substitutes matched text. Capture groups — parenthesized sub-patterns — remember the substring they matched and surface it as $1, $2, and so on. Lookahead ((?=...), (?!...)) and lookbehind ((?<=...), (?<!...)) assert context without consuming characters, letting you match a token only when it is preceded or followed by something specific.

Common use cases

  • Validating emails, phone numbers, and other structured inputs
  • Extracting every URL, hashtag, or mention from a block of text
  • Scrubbing or redacting sensitive tokens from a log file
  • Building a replace call that reorders captured fields
  • Debugging why a pattern matches (or fails to match) before deploying it

Worked example

Pattern with two capture groups, tested against a sample string:

Pattern:  /(\w+)@(\w+\.\w+)/g
Flags:    g
String:   contact ada@example.com or bob@test.org

The engine finds two full matches and captures the local part and the domain of each:

Match 1: ada@example.com
  group 1 (local):   ada
  group 2 (domain):  example.com
Match 2: bob@test.org
  group 1 (local):   bob
  group 2 (domain):  test.org

With those groups you can run replace using $2 then $1 to swap their order — capture groups are what make a regex more than a yes/no test.

Frequently asked questions

What is the difference between a regex literal and the constructor?

A literal such as /abc/gi is compiled once when the script loads and needs no extra escaping of backslashes. The constructor new RegExp('abc', 'gi') accepts a runtime string, which is useful when the pattern is built from variables but requires you to double-escape backslashes in the source.

What do the common flags do?

g finds every match, i is case-insensitive, m makes ^ and $ match line boundaries, s lets the dot match newlines, u enables full Unicode handling, and y anchors each match at lastIndex. You can combine them, for example gi.

How do capture groups work?

Parentheses form a capture group that remembers the substring it matched. match and matchAll return the full match plus each group, replace can reference them as $1 and $2, and exec exposes them on the result array.

Are my inputs sent to a server?

No. Pattern compilation, matching, and substitution all run in your browser through the native RegExp engine. Patterns and test strings stay on your device.

์ •๊ทœ์‹ ํ…Œ์Šคํ„ฐ๋ž€?

์ •๊ทœ์‹(Regular Expression)์€ ํ…์ŠคํŠธ๋ฅผ ๊ฒ€์‚ฌยท์ถ”์ถœยท์น˜ํ™˜ํ•˜๊ธฐ ์œ„ํ•œ ๊ฐ„๊ฒฐํ•œ ํŒจํ„ด ์–ธ์–ด์ž…๋‹ˆ๋‹ค. JavaScript์—์„œ๋Š” RegExp ๊ฐ์ฒด์— ์ž๋ฆฌ ์žก๊ณ  ์žˆ์œผ๋ฉฐ ํผ ๊ฒ€์ฆ, ๋ผ์šฐํŠธ ๋งค์นญ, ๋กœ๊ทธ ๋ถ„์„, ํŽธ์ง‘๊ธฐ์˜ ์ฐพ๊ธฐ๋ฐ”๊พธ๊ธฐ๊นŒ์ง€ ๋‘๋ฃจ ์“ฐ์ž…๋‹ˆ๋‹ค. ์ด ํ…Œ์Šคํ„ฐ๋Š” ํŒจํ„ด์„ ์ƒ˜ํ”Œ ๋ฌธ์ž์—ด์— ๋Œ€ํ•ด ์‹ค์‹œ๊ฐ„์œผ๋กœ ์ปดํŒŒ์ผํ•ด ๋ชจ๋“  ์ผ์น˜๋ฅผ ๊ฐ•์กฐ ํ‘œ์‹œํ•˜๊ณ  ์น˜ํ™˜๊นŒ์ง€ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ฉ๋‹ˆ๋‹ค — ๋ชจ๋‘ ๋ธŒ๋ผ์šฐ์ € ์•ˆ์—์„œ ์ฒ˜๋ฆฌ๋˜๋ฏ€๋กœ ํŒจํ„ด๊ณผ ์ž…๋ ฅ์ด ๊ธฐ๊ธฐ๋ฅผ ๋– ๋‚˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

์ž‘๋™ ๋ฐฉ์‹

ํŒจํ„ด์€ ๋‘ ๊ฐ€์ง€ ๋ฐฉ์‹์œผ๋กœ ์ž‘์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. ์Šฌ๋ž˜์‹œ๋กœ ๊ฐ์‹ผ ์ •๊ทœ์‹ ๋ฆฌํ„ฐ๋Ÿด /\d+/g์€ ์Šคํฌ๋ฆฝํŠธ๊ฐ€ ๋กœ๋“œ๋  ๋•Œ ์ปดํŒŒ์ผ๋ฉ๋‹ˆ๋‹ค. ์ƒ์„ฑ์ž ํ˜•ํƒœ new RegExp("\\d+", "g")๋Š” ๋Ÿฐํƒ€์ž„ ๋ฌธ์ž์—ด์„ ๋ฐ›์œผ๋ฉฐ, ๋ณ€์ˆ˜๋กœ ํŒจํ„ด์„ ์กฐ๋ฆฝํ•  ๋•Œ ํ•„์ˆ˜์ ์ž…๋‹ˆ๋‹ค — ๋‹ค๋งŒ ๋ฌธ์ž์—ด ๋‹จ๊ณ„์—์„œ ๋ฐฑ์Šฌ๋ž˜์‹œ ํ•˜๋‚˜๋ฅผ ์†Œ๋น„ํ•˜๋ฏ€๋กœ ๋‘ ๊ฐœ๋กœ ๊ฒน์ณ ์จ์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋‹ซ๋Š” ์Šฌ๋ž˜์‹œ ๋’ค(๋˜๋Š” ์ƒ์„ฑ์ž์˜ ๋‘ ๋ฒˆ์งธ ์ธ์ž๋กœ)์— ํ”Œ๋ž˜๊ทธ๊ฐ€ ์˜ต๋‹ˆ๋‹ค. g๋Š” ์ „์—ญ(์ฒซ ์ผ์น˜๊ฐ€ ์•„๋‹ˆ๋ผ ๋ชจ๋“  ์ผ์น˜), i๋Š” ๋Œ€์†Œ๋ฌธ์ž ๋ฌด์‹œ, m์€ ๋ฉ€ํ‹ฐ๋ผ์ธ(^๊ณผ $๊ฐ€ ์ค„ ๊ฒฝ๊ณ„์— ์ผ์น˜), s๋Š” dotAll(์ ์ด ์ค„๋ฐ”๊ฟˆ์—๋„ ์ผ์น˜), u๋Š” ์™„์ „ํ•œ ์œ ๋‹ˆ์ฝ”๋“œ ์ฒ˜๋ฆฌ, y๋Š” sticky(lastIndex์— ๊ณ ์ •ํ•ด ์ผ์น˜)์ž…๋‹ˆ๋‹ค.

์ปดํŒŒ์ผ๋œ ํŒจํ„ด์„ ์†Œ๋น„ํ•˜๋Š” ๋ฉ”์„œ๋“œ๋Š” ์—ฌ๋Ÿฟ์ž…๋‹ˆ๋‹ค. test()๋Š” ๋ถˆ๋ฆฌ์–ธ์„ ๋ฐ˜ํ™˜ํ•˜๊ณ , exec()๋Š” ์บก์ฒ˜ ๊ทธ๋ฃน์„ ํฌํ•จํ•œ ์ผ์น˜ ๊ฐ์ฒด ํ•˜๋‚˜๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋ฉฐ, String.match()๋Š” ์ฒซ ์ผ์น˜(๋˜๋Š” g ํ”Œ๋ž˜๊ทธ์ผ ๋•Œ ๋ชจ๋“  ์ผ์น˜)๋ฅผ, String.matchAll()๋Š” ๊ฐ ์ผ์น˜์™€ ๊ทธ๋ฃน์„ ์ˆœํšŒํ•˜๊ณ , String.replace()๋Š” ์ผ์น˜ํ•œ ํ…์ŠคํŠธ๋ฅผ ์น˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ์บก์ฒ˜ ๊ทธ๋ฃน — ๊ด„ํ˜ธ๋กœ ๊ฐ์‹ผ ํ•˜์œ„ ํŒจํ„ด —์€ ์ž์‹ ์ด ์ผ์น˜ํ•œ ๋ถ€๋ถ„ ๋ฌธ์ž์—ด์„ ๊ธฐ์–ตํ•˜๊ณ  $1, $2 ์‹์œผ๋กœ ๋…ธ์ถœํ•ฉ๋‹ˆ๋‹ค. ๋ฃฉ์–ดํ—ค๋“œ((?=...), (?!...))์™€ ๋ฃฉ๋น„ํ•˜์ธ๋“œ((?<=...), (?<!...))๋Š” ๋ฌธ์ž๋ฅผ ์†Œ๋น„ํ•˜์ง€ ์•Š๊ณ  ๋ฌธ๋งฅ์„ ๋‹จ์–ธํ•˜๋ฏ€๋กœ, ์–ด๋–ค ํ† ํฐ์ด ํŠน์ • ๋ฌด์–ธ๊ฐ€์˜ ์•ž(๋˜๋Š” ๋’ค)์— ์žˆ์„ ๋•Œ๋งŒ ์ผ์น˜์‹œํ‚ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์ž์ฃผ ์“ฐ๋Š” ๊ฒฝ์šฐ

  • ์ด๋ฉ”์ผ, ์ „ํ™”๋ฒˆํ˜ธ ๋“ฑ ๊ตฌ์กฐํ™”๋œ ์ž…๋ ฅ ๊ฒ€์ฆํ•˜๊ธฐ
  • ํ…์ŠคํŠธ ๋ธ”๋ก์—์„œ ๋ชจ๋“  URL, ํ•ด์‹œํƒœ๊ทธ, ๋ฉ˜์…˜ ์ถ”์ถœํ•˜๊ธฐ
  • ๋กœ๊ทธ ํŒŒ์ผ์—์„œ ๋ฏผ๊ฐํ•œ ํ† ํฐ์„ ์Šคํฌ๋Ÿฝํ•˜๊ฑฐ๋‚˜ ๋งˆ์Šคํ‚นํ•˜๊ธฐ
  • ์บก์ฒ˜ํ•œ ํ•„๋“œ ์ˆœ์„œ๋ฅผ ๋ฐ”๊พธ๋Š” replace ํ˜ธ์ถœ ๋งŒ๋“ค๊ธฐ
  • ํŒจํ„ด์ด ์ผ์น˜ํ•˜๋Š”์ง€(๋˜๋Š” ์‹คํŒจํ•˜๋Š”์ง€) ๋ฐฐํฌ ์ „์— ๋””๋ฒ„๊น…ํ•˜๊ธฐ

์‚ฌ์šฉ ์˜ˆ

๋‘ ๊ฐœ์˜ ์บก์ฒ˜ ๊ทธ๋ฃน์„ ๊ฐ€์ง„ ํŒจํ„ด์„ ์ƒ˜ํ”Œ ๋ฌธ์ž์—ด์— ๋Œ€ํ•ด ๊ฒ€์‚ฌํ•ฉ๋‹ˆ๋‹ค:

ํŒจํ„ด:  /(\w+)@(\w+\.\w+)/g
ํ”Œ๋ž˜๊ทธ: g
๋ฌธ์ž์—ด: contact ada@example.com or bob@test.org

์—”์ง„์€ ๋‘ ๊ฐœ์˜ ์ „์ฒด ์ผ์น˜๋ฅผ ์ฐพ๊ณ  ๊ฐ๊ฐ์˜ ๋กœ์ปฌ ํŒŒํŠธ์™€ ๋„๋ฉ”์ธ์„ ์บก์ฒ˜ํ•ฉ๋‹ˆ๋‹ค:

์ผ์น˜ 1: ada@example.com
  ๊ทธ๋ฃน 1 (local):   ada
  ๊ทธ๋ฃน 2 (domain):  example.com
์ผ์น˜ 2: bob@test.org
  ๊ทธ๋ฃน 1 (local):   bob
  ๊ทธ๋ฃน 2 (domain):  test.org

์ด ๊ทธ๋ฃน๋“ค๋กœ replace์—์„œ $2์™€ $1์„ ์จ ์ˆœ์„œ๋ฅผ ๋ฐ”๊พธ๊ฑฐ๋‚˜ ๋„๋ฉ”์ธ๋งŒ ๋ฝ‘์•„๋‚ผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค — ์บก์ฒ˜ ๊ทธ๋ฃน์ด ์ •๊ทœ์‹์„ ๋‹จ์ˆœํ•œ ์˜ˆ/์•„๋‹ˆ์˜ค ๊ฒ€์‚ฌ ์ด์ƒ์œผ๋กœ ๋งŒ๋“ญ๋‹ˆ๋‹ค.

์ž์ฃผ ๋ฌป๋Š” ์งˆ๋ฌธ

์ •๊ทœ์‹ ๋ฆฌํ„ฐ๋Ÿด๊ณผ ์ƒ์„ฑ์ž์˜ ์ฐจ์ด๋Š”?

/abc/gi ๊ฐ™์€ ๋ฆฌํ„ฐ๋Ÿด์€ ์Šคํฌ๋ฆฝํŠธ๊ฐ€ ๋กœ๋“œ๋  ๋•Œ ํ•œ ๋ฒˆ ์ปดํŒŒ์ผ๋˜๋ฉฐ ๋ฐฑ์Šฌ๋ž˜์‹œ๋ฅผ ์ถ”๊ฐ€๋กœ ์ด์Šค์ผ€์ดํ”„ํ•  ํ•„์š”๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค. new RegExp('abc', 'gi') ์ƒ์„ฑ์ž๋Š” ๋Ÿฐํƒ€์ž„ ๋ฌธ์ž์—ด์„ ๋ฐ›์•„ ๋ณ€์ˆ˜๋กœ ํŒจํ„ด์„ ๋งŒ๋“ค ๋•Œ ์œ ์šฉํ•˜์ง€๋งŒ, ์†Œ์Šค์—์„œ ๋ฐฑ์Šฌ๋ž˜์‹œ๋ฅผ ๋‘ ๋ฒˆ ์จ์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์ฃผ์š” ํ”Œ๋ž˜๊ทธ๋Š” ๋ฌด์—‡์„ ํ•˜๋‚˜์š”?

g๋Š” ๋ชจ๋“  ์ผ์น˜๋ฅผ ์ฐพ๊ณ , i๋Š” ๋Œ€์†Œ๋ฌธ์ž๋ฅผ ๋ฌด์‹œํ•˜๋ฉฐ, m์€ ^์™€ $๊ฐ€ ์ค„ ๊ฒฝ๊ณ„์— ์ผ์น˜ํ•˜๊ฒŒ ํ•˜๊ณ , s๋Š” ์ ์ด ์ค„๋ฐ”๊ฟˆ์—๋„ ์ผ์น˜ํ•˜๊ฒŒ ํ•˜๋ฉฐ, u๋Š” ์™„์ „ํ•œ ์œ ๋‹ˆ์ฝ”๋“œ ์ฒ˜๋ฆฌ๋ฅผ ์ผœ๊ณ , y๋Š” lastIndex์— ์ผ์น˜๋ฅผ ๊ณ ์ •ํ•ฉ๋‹ˆ๋‹ค. gi์ฒ˜๋Ÿผ ์กฐํ•ฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์บก์ฒ˜ ๊ทธ๋ฃน์€ ์–ด๋–ป๊ฒŒ ๋™์ž‘ํ•˜๋‚˜์š”?

๊ด„ํ˜ธ๋Š” ์ž์‹ ์ด ์ผ์น˜ํ•œ ๋ถ€๋ถ„ ๋ฌธ์ž์—ด์„ ๊ธฐ์–ตํ•˜๋Š” ์บก์ฒ˜ ๊ทธ๋ฃน์„ ๋งŒ๋“ญ๋‹ˆ๋‹ค. match์™€ matchAll์€ ์ „์ฒด ์ผ์น˜์™€ ๊ฐ ๊ทธ๋ฃน์„ ๋ฐ˜ํ™˜ํ•˜๊ณ , replace๋Š” $1๊ณผ $2๋กœ ์ฐธ์กฐํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, exec๋Š” ๊ฒฐ๊ณผ ๋ฐฐ์—ด์— ๋…ธ์ถœํ•ฉ๋‹ˆ๋‹ค.

์ž…๋ ฅ์ด ์„œ๋ฒ„๋กœ ์ „์†ก๋˜๋‚˜์š”?

์•„๋‹™๋‹ˆ๋‹ค. ํŒจํ„ด ์ปดํŒŒ์ผ, ์ผ์น˜, ์น˜ํ™˜์€ ๋ชจ๋‘ ๋ธŒ๋ผ์šฐ์ €์—์„œ ๋„ค์ดํ‹ฐ๋ธŒ RegExp ์—”์ง„์œผ๋กœ ์‹คํ–‰๋ฉ๋‹ˆ๋‹ค. ํŒจํ„ด๊ณผ ํ…Œ์ŠคํŠธ ๋ฌธ์ž์—ด์€ ๊ธฐ๊ธฐ์— ๋จธ๋ญ…๋‹ˆ๋‹ค.