Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
Sponsors
An explanation of your regex will be automatically generated as you type.
Detailed match information will be displayed here automatically.
  • All Tokens
  • Common Tokens
  • General Tokens
  • Anchors
  • Meta Sequences
  • Quantifiers
  • Group Constructs
  • Character Classes
  • Flags/Modifiers
  • Substitution
  • A single character of: a, b or c
    [abc]
  • A character except: a, b or c
    [^abc]
  • A character in the range: a-z
    [a-z]
  • A character not in the range: a-z
    [^a-z]
  • A character in the range: a-z or A-Z
    [a-zA-Z]
  • Character class intersection
    [\w&&[^\d]]
  • Any single character
    .
  • Alternate - match either a or b
    a|b
  • Any whitespace character
    \s
  • Any non-whitespace character
    \S
  • Any digit
    \d
  • Any non-digit
    \D
  • Any word character
    \w
  • Any non-word character
    \W
  • Non-capturing group
    (?:...)
  • Capturing group
    (...)
  • Zero or one of a
    a?
  • Zero or more of a
    a*
  • One or more of a
    a+
  • Exactly 3 of a
    a{3}
  • 3 or more of a
    a{3,}
  • Between 3 and 6 of a
    a{3,6}
  • Start of string
    ^
  • End of string
    $
  • A word boundary
    \b
  • Non-word boundary
    \B

Regular Expression
Processing...

Test String

Code Generator

Generated Code

const regex = /<svg\b[^>]* (viewBox=\"(\b[^"]*)\").*?>([\s\S]*?)<\/svg>/gmi; // Alternative syntax using RegExp constructor // const regex = new RegExp('<svg\\b[^>]* (viewBox=\\"(\\b[^"]*)\\").*?>([\\s\\S]*?)<\\\/svg>', 'gmi') const str = `<svg version="1.1" xmlns="http://www.w3.org/2000/svg" width="28" height="32" viewBox="0 0 28 32"><title>guarantee</title><path fill="#1a3347" d="M26.261 13.056v-6.823c-6.946 0.047-10.42-3.42-12.29-5.181-1.869 1.761-5.344 5.228-12.29 5.181v6.823c0 0-0.895 13.353 12.29 18.043 13.185-4.69 12.29-18.043 12.29-18.043z"></path><path fill="#fff" d="M13.972 29.466l-0.202-0.081c-4.627-1.839-7.805-5.066-9.447-9.59-1.295-3.57-1.113-6.612-1.111-6.642l0.004-0.063-0.001-5.366 0.496-0.046c3.755-0.346 6.996-1.729 9.906-4.226l0.355-0.305 0.356 0.306c2.91 2.498 6.15 3.881 9.906 4.226l0.496 0.046 0.003 5.435c0.002 0.027 0.173 3.19-1.166 6.782-1.658 4.447-4.818 7.624-9.393 9.443l-0.202 0.080zM4.307 8.716l-0.005 4.512c-0.002 0.028-0.148 2.897 1.048 6.195 1.507 4.152 4.406 7.133 8.621 8.866 4.167-1.713 7.050-4.648 8.571-8.728 1.249-3.351 1.1-6.304 1.099-6.333l-0.004-0.068-0.001-4.442c-3.628-0.423-6.799-1.78-9.665-4.135-2.865 2.355-6.036 3.712-9.664 4.135z"></path></svg>`; // Reset `lastIndex` if this regex is defined globally // regex.lastIndex = 0; let m; while ((m = regex.exec(str)) !== null) { // This is necessary to avoid infinite loops with zero-width matches if (m.index === regex.lastIndex) { regex.lastIndex++; } // The result can be accessed through the `m`-variable. m.forEach((match, groupIndex) => { console.log(`Found match, group ${groupIndex}: ${match}`); }); }

Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions