plain/devtools home

Test a regex in JavaScript

Type a pattern and sample text in the tool above to see matches highlighted. In code, re.test(str) returns true or false, str.match(re) returns the matches and str.matchAll(re) iterates all of them with positions.

Last reviewed 2026-11-04.

regex-testersampless sample
Flags
Highlighted matches

Uses your browser's own RegExp engine (ECMAScript), in a background worker. A run that takes longer than 1 second is stopped, so a pattern that backtracks catastrophically cannot freeze this tab.

never leaves your browser

Worked example

$ /^\d{3}-\d{4}$/.test('555-1234')   // true
/^\d{3}-\d{4}$/.test('x555-1234')  // false

'2026-11-04'.match(/(?<y>\d{4})-(?<m>\d{2})-(?<d>\d{2})/).groups
// { y: '2026', m: '11', d: '04' }

[...'a1b22c333'.matchAll(/\d+/g)].map(m => m[0] + '@' + m.index)
// ['1@1', '22@3', '333@6']

The global flag trap

With the g (or y) flag, test() remembers lastIndex between calls on the same regex object:

$ const re = /a/g;
re.test('aa')  // true
re.test('aa')  // true
re.test('aa')  // false (lastIndex was past the end)

Drop the g flag when you only need a yes or no, or create the regex inside the function.

Flags

  • g all matches, i ignore case, m ^ and $ match at each line.
  • s lets . match a newline: /a.c/.test("a\nc") is false, /a.c/s.test("a\nc") is true.
  • u full Unicode matching, d adds match indices.

Common mistakes

  • Building a regex from a string and forgetting to double the backslash: new RegExp("\\.") matches a dot, new RegExp("\.") matches any character.
  • Nested quantifiers such as (a+)+ can freeze the page; see catastrophic backtracking.

Running this on a server

The tester runs in your browser. If your regex validates input on a server, the hosting guide compares small hosts.

Frequently asked questions

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

test() returns a boolean. match() returns the matched text and groups, or null.

Why does test() alternate between true and false?

The g flag keeps lastIndex on the regex object. Remove g or reset lastIndex to 0.

Does this use the JavaScript engine?

Yes. It runs your browser's own RegExp, so results match what your code will do.

Sources

Related

esc
↑↓ move↵ open? all shortcuts

Keyboard shortcuts

Cmd or Ctrl shortcuts always work.
Everywhere
Everywhere
Open the command palette
CtrlK
Open the palette (outside a text field)
/
Show these shortcuts
?
Toggle light and dark theme
t
Go home
gh
Go to all tools
gt
On a tool page
On a tool page
Run the main action
Ctrl↵
Copy the output
c
Load the next sample
s
Focus the input
i
Leave a text field
Esc
Previous or next tool
[]
In the palette
In the palette
Move the selection
↑↓
Open the selected item
↵
Close
Esc