Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8
  • .NET 7.0 (C#)
  • Rust
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests

Tools

Sponsors
There are currently no sponsors. Become a sponsor today!
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]
  • 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
No Match

/
/
gm

Test String

Code Generator

Generated Code

const regex = /<DT><A HREF=\"(.*?)(?=\")\" ADD_DATE=\"(\d+)\".*?>([\s\S]+?)<\/A>/gm; // Alternative syntax using RegExp constructor // const regex = new RegExp('<DT><A HREF=\\"(.*?)(?=\\")\\" ADD_DATE=\\"(\\d+)\\".*?>([\\s\\S]+?)<\\\/A>', 'gm') const str = `<!DOCTYPE NETSCAPE-Bookmark-file-1> <!-- This is an automatically generated file. It will be read and overwritten. DO NOT EDIT! --> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=UTF-8"> <TITLE>Bookmarks</TITLE> <H1>Bookmarks</H1> <DL><p> <DT><A HREF="https://www.programcreek.com/2011/03/java-write-to-a-file-code-example/" ADD_DATE="1508652899" ICON="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABVUlEQVQ4jcWSwYoTURBFz30vDTG8xcTgIhsHYdwFI7jRf/G3/AT/pA0mkF9woSLBTkyMbfKa6a5yIQmIDCIRvLu6VB2qLiV3F/9TcverSwGbvx1y4HS33N0v2aB3F+BkuzsxxrPf3LZkhxQDkhMkIemXIeDsxRi1Wq0o38z4vvvCxzbw6t2RGCUjEMxMXddJkkIIAmRmMjOFELTZbFgul6qqzyrfLnT/9ps+NdLr95mISW3beoyR7XZLXdeMRiMGgwHuTs6Z2WzG8XikKApy0/BgeMWz5y/40IhH9/QzxPV67YvFgq7r6Pf7TCYTxuMx8/mcqqooigJ3J4RAzpnr64dMp09lZq66rq0sSw6HA0VR0LYtIQRSSuz3e3q93m/ZNE3Dk+mUxzc39KqqspQSw+HwHKQkuq4jpXSuTxBJmBlfdztyzv/gD4CXlwAultw9/rntbv0A1ZC8BgHlLSQAAAAASUVORK5CYII=">How to Write a File Line by Line in Java?</A> <DT><A HREF="https://stackoverflow.com/questions/2885173/how-do-i-create-a-file-and-write-to-it-in-java" ADD_DATE="1508652914">How do I create a file and write to it in Java? - Stack Overflow</A> <DT><A HREF="https://www.javacodegeeks.com/2010/05/getting-started-with-youtube-java-api.html" ADD_DATE="1508996959" ICON="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABvUlEQVQ4jZWTP2sUURTFf3dmxcUUCVgFHZwU1m66dBmbLOkmXRy2WBtBDMh+gjCfIEg2hAiCi8tgY1axkKTZEQsTm52tLTISUoo2gQ1m3rXYP4TdjCavu+8ezj2cey5c8wV151ew5bSGdeG6BAoJSjqs5V/gqWC/lFnqKzwoGAlPo6VkHHOpgmDLqQLsflUXWBcgs7QLXI0AZQMktSA0oz+9d6uy5xsoqTB99qZcmyAoVj+5nOMefu8kzu1vDVMwyZ3pTnzycz7kBqk5lyMAUQBqEx7crOy1BPx+ZR6uLDxZF/CitWMZ9DsCpb52M9d7vZwWKpt3PSPSRiXcPaTLiMDyRGhg5PPqtut+/PJyJhNeiDEzKpoUKf7uDRU8qjttC/nw7mAnUaznAl3byPvTaCm5OLXXLE9sLXeNQd05UkhbB68A9QBsI/Pjq8wNkkIqkKIGRACJL8PlKrgYorNmeQUG+VAWo7Xjx0OclUeQWWzQD5E/FeyXBrIWgerqtuv+lwA1o7xndt9EY9uhse25t0/TUS//mEQbID/AxAv3d9zZutMW86cWPTu5mom95nIMxACzm44v4InaHmP38Bf/laoOI/FjiQAAAABJRU5ErkJggg==">Getting Started with YouTube Java API | Java Code Geeks - 2017</A> </DL><p>`; // 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