Bak-O-Soft™

Javascript RegExp builder

Javascript RegExp builder:

Literal constructor (/ /) Doublequote string constructor (" ") Singlequote string constructor (' ') Raw string (for editor search)
Regex options:

Build and test regular expressions using your browser's Javascript Regular expression engine.

Note: This is not an emulator (like some regex testers on the web). It directly calls your browser's ' Javascript Regular expression engine. What you see is what you get.

The page supports testing String match, String matchAll, RegExp exec, String split, String replace and String replaceAll.

The results are shown in easy to understand tables showing all matches and all groups.

Enter regular expression in code format (like you would in code).

Supports setting all javascript RegExp options.

Syntax errors will be reported as you type. When errors have been fixed a RegExp construtor will be shown, ready to copy/paste.

The syntax you use depends on the constructor format, you have chosen (the tabs).

You can choose between literal verbatim RegExp constructor and string constructors, using either doublequotes or singlequotes. Switching between them will convert the regular expression to that format.

RegExp constructor format:

  1. Literal verbatim constructor (@/ /)

    : Here you don't need to double escape control characters, example '\n' matches a newline.
    Slashes (/) must be escaped, example '\/' matches one slash.
  2. Literal double quoted string (" ")

    : Here you need to double escape all control characters, example '\\n' matches a newline.
    Doublequotes must be escaped, example '\\"' matches one doublequote.
  3. Literal single quoted string (' ')

    : Here you need to double escape all control characters, example '\\n' matches a newline.
    Singlequotes must be escaped, example '\\"' matches one doublequote.
  4. Raw string (for editor search)

    : Here you use the raw regex string - without any escapes.
    This is suitable for direct input in your editors search box.

The 'RegExp constructor' will show the RegExp constructor based on your RegExp and options, ready to copy and paste into your code.
Switching to the other constructor types (by clicking the tabs) will also change the constructor to that format.

Which method to use in your code:

  1. String match

    is the universal way, if you only want one match (without the 'global' flag). That will give you access to groups. With global flag set, it only returns matches, no information about groups.
  2. String matchAll

    is the newer way to multi-match. It must have the global flag set. Then it returns all matches, including info on all groups.
  3. RegExp exec

    is the old original method in javascript. It is hard to use, if you don't know the syntax.
  4. String split

    is used to split the tekst on every match into an array.
  5. String replace

    will only replace the first match, when global flag is not set. With global flag set, it replaces all matches.
  6. String replaceAll

    must have the global flag set and it replaces all matches (like 'String replace' will global flag set).

When you have tested your RegExp, you can save it and share the link.