Regex to JavaScript

Turn a regular expression and flags into paste ready JavaScript with a literal form, a constructor and examples.

Write a regex and get JavaScript

Pattern: —
Flags: —
Status: —
Both forms are generated: a regex literal you can paste straight in and a RegExp constructor built from a string.

How to use the Regex to JavaScript

  1. Type the regular expression pattern you want to use.
  2. Pick the flags and paste a sample text to test against.
  3. Generate the code and copy the form you need.

Features

Advertisement

Frequently Asked Questions

Common questions about the free online regex to javascript.

Write it as a literal between slashes such as /abc/g, or build it from a string with the RegExp constructor.
A literal is compiled once when the script loads, while the constructor form can build a pattern from a variable at runtime.
g finds every match, i ignores letter case, m treats each line as a separate string and s lets a dot match newlines.
Call the test method, which returns true or false, while the match method returns the matched text instead.
An unbalanced bracket or a trailing backslash breaks the expression, and the tool tells you when that happens.
Put a backslash before it, so a literal dot becomes a backslash and a dot in the pattern.
Yes. With g the global matching methods return every match, and a regex object also remembers its last position.
Yes. Escape the input first, then pass the string to the RegExp constructor so special characters are treated literally.
Yes. The generator is free, runs locally in your browser and needs no account or sign-up.

Last updated: October 10, 2026