Regex to Code (JS, Python, Go, Java, PHP, C#, Ruby, Rust)

Paste a regex once and get ready-to-paste declarations for JavaScript, Python, Go, Java, PHP, C#, Ruby and Rust.

Use the tool

Why this tool exists

The tool escapes the pattern for each language's string rules (raw strings in Python, Go and Rust, doubled backslashes in Java, verbatim strings in C#, delimiters and flags in PHP) and maps the ignore-case, multiline and dotall options to each language's flags. It converts named groups to Python's (?P<name>) form and warns when Go or Rust cannot compile lookarounds or backreferences.

Regex dialects differ beyond escaping: Unicode behaviour of \w and \b, possessive quantifiers and \p classes vary. Test the snippet in the target language.

No data is sent anywhere: the work happens in your browser, so you can use it offline once the page has loaded.

How to use it

  1. Paste the pattern without slashes.
  2. Tick ignore case, multiline or dotall if needed.
  3. Copy the snippet for your language.
  4. Run it against test strings in that language.

Frequently asked questions

Why does Go not accept my pattern?

Go uses RE2, which has no lookahead, lookbehind or backreferences, so the tool shows a warning.

Do named groups work everywhere?

Syntax varies: (?<n>) in JavaScript, Java, .NET and Ruby; (?P<n>) in Python and Go.

Is my pattern uploaded?

No. It is transformed in the page.

Is my data sent anywhere?

No. Everything is processed in your browser, and the page makes no network requests with your input.