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

Substitution
Processing...

Code Generator

Generated Code

const regex = /(href|src)=\"\//gm; // Alternative syntax using RegExp constructor // const regex = new RegExp('(href|src)=\\"\\\/', 'gm') const str = `"<!DOCTYPE html><html lang="en" class="notion-html"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,height=device-height,initial-scale=1,maximum-scale=1,user-scalable=no,viewport-fit=cover"><title>Notion – The all-in-one workspace for your notes, tasks, wikis, and databases.</title><meta name="description" content="A new tool that blends your everyday work apps into one. It's the all-in-one workspace for you and your team"><script type="text/javascript">window.__webStartTime=Date.now()</script><meta name="twitter:card" content="summary_large_image"><meta name="twitter:site" content="@NotionHQ"><meta name="twitter:title" content="Notion – The all-in-one workspace for your notes, tasks, wikis, and databases."><meta name="twitter:description" content="A new tool that blends your everyday work apps into one. It's the all-in-one workspace for you and your team"><meta name="twitter:url" content="https://www.notion.so"><meta name="twitter:image" content="https://www.notion.so/images/meta/default.png"><meta property="og:site_name" content="Notion"><meta property="og:type" content="website"><meta property="og:url" content="https://www.notion.so"><meta property="og:title" content="Notion – The all-in-one workspace for your notes, tasks, wikis, and databases."><meta property="og:description" content="A new tool that blends your everyday work apps into one. It's the all-in-one workspace for you and your team"><meta property="og:image" content="https://www.notion.so/images/meta/default.png"><meta property="og:locale" content="en_US"><link rel="shortcut icon" type="image/x-icon" href="/images/favicon.ico"><link rel="apple-touch-icon" href="/images/logo-ios.png"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-itunes-app" content="app-id=1232780281"><meta name="format-detection" content="telephone=no"><meta name="msapplication-tap-highlight" content="no"><link href="/print.b31f28aa.css" rel="stylesheet" media="print"><link href="/vendors~main-aa07f589b8b4b537cd5a.css" rel="stylesheet"><link href="/app-360d995418be563505cc.css" rel="stylesheet"></head><body class="notion-body"><script type="text/javascript">var theme="light",localThemeKey="theme",themeRecord=localStorage.getItem("theme");if(themeRecord){var parsed=JSON.parse(themeRecord);parsed&&parsed.mode&&(theme=parsed.mode)}"dark"===theme&&document.body.classList.add("dark")</script><style>body{background:#fff}body.dark{background:#2f3437}.initial-loading-spinner{-webkit-animation:rotate 1s linear infinite;animation:rotate 1s linear infinite;-webkit-transform-origin:center center;transform-origin:center center;width:1em;height:1em;opacity:.5;display:block;pointer-events:none}@-webkit-keyframes rotate{0%{-webkit-transform:rotate(0) translateZ(0);transform:rotate(0) translateZ(0)}100%{-webkit-transform:rotate(360deg) translateZ(0);transform:rotate(360deg) translateZ(0)}}@keyframes rotate{0%{-webkit-transform:rotate(0) translateZ(0);transform:rotate(0) translateZ(0)}100%{-webkit-transform:rotate(360deg) translateZ(0);transform:rotate(360deg) translateZ(0)}}</style><div id="initial-loading-spinner" style="position:absolute;top:0;bottom:0;left:0;right:0;display:flex;align-items:center;justify-content:center;opacity:0"><div class="initial-loading-spinner" style="width:24px;height:24px"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:sketch="http://www.bohemiancoding.com/sketch/ns" width="100%" height="100%" viewBox="0 0 24 24" version="1.1" data-ember-extension="1"><defs><linearGradient x1="28.1542969%" y1="63.7402344%" x2="74.6289062%" y2="17.7832031%" id="linearGradient-1"><stop stop-color="rgba(164, 164, 164, 1)" offset="0%"/><stop stop-color="rgba(164, 164, 164, 0)" stop-opacity="0" offset="100%"/></linearGradient></defs><g id="Page-1" stroke="none" stroke-width="1" fill="none"><g transform="translate(-236.000000, -286.000000)"><g transform="translate(238.000000, 286.000000)"><circle id="Oval-2" stroke="url(#linearGradient-1)" stroke-width="4" cx="10" cy="12" r="10"/><path d="M10,2 C4.4771525,2 0,6.4771525 0,12" id="Oval-2" stroke="rgba(164, 164, 164, 1)" stroke-width="4"/><rect id="Rectangle-1" fill="rgba(164, 164, 164, 1)" x="8" y="0" width="4" height="4" rx="8"/></g></g></g></svg></div></div><script type="text/javascript">var isElectron="undefined"!=typeof global||window.__isElectron,isReactNative=/ReactNative/.test(navigator.userAgent),showSpinner=isElectron||isReactNative;if(showSpinner){var spinner=document.getElementById("initial-loading-spinner");spinner&&(spinner.style.opacity=1)}</script><div id="notion-app"></div><script type="text/javascript" src="/vendors~main-43c644cb58b7f4a0b032.js"></script><script type="text/javascript" src="/app-24e0cf89f2d116fc27a1.js"></script></body></html>"`; const subst = ``; // The substituted value will be contained in the result variable const result = str.replace(regex, subst); console.log('Substitution result: ', result);

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