<!doctypehtml><html lang=en><meta charset=utf-8><meta content="7 Days"name=revisit-after><meta content="copyright (c) RexEgg.com --- ALL RIGHTS RESERVED"name=dcterms.rightsHolder><meta content=width=device-width,initial-scale=1 name=viewport><link href=http://a.yu8.us/icon_rexegg.png rel=icon><link href=https://yu8.us/0_mycss-210104.html?cat=regex&com=1 media=screen,print rel=stylesheet><link href=https://yu8.us/google_fonts/google-lato-merriweather.css rel=stylesheet><meta content="Regular Expressions Syntax Reference. Includes tables showing syntax, examples and matches."name=description><title>
   Regex Cheat Sheet
  </title><script src=https://www.google.com/recaptcha/api.js></script><body><header "javascript:void(0)" class=sitebanner id=the_banner onclick=close_left_menu()></header><nav class=topmenu><table class="glossymenu mobile_only"cellpadding=0><colgroup><col class=w80><col class=w570></colgroup><tbody><tr><td style=vertical-align:top;><span class=hamburger onclick=open_left_menu()> <img alt=Menu class=w50 src=data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/PjwhRE9DVFlQRSBzdmcgIFBVQkxJQyAnLS8vVzNDLy9EVEQgU1ZHIDEuMS8vRU4nICAnaHR0cDovL3d3dy53My5vcmcvR3JhcGhpY3MvU1ZHLzEuMS9EVEQvc3ZnMTEuZHRkJz48c3ZnIGhlaWdodD0iMzJweCIgaWQ9IkxheWVyXzEiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDMyIDMyOyIgdmVyc2lvbj0iMS4xIiB2aWV3Qm94PSIwIDAgMzIgMzIiIHdpZHRoPSIzMnB4IiB4bWw6c3BhY2U9InByZXNlcnZlIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIj48cGF0aCBkPSJNNCwxMGgyNGMxLjEwNCwwLDItMC44OTYsMi0ycy0wLjg5Ni0yLTItMkg0QzIuODk2LDYsMiw2Ljg5NiwyLDhTMi44OTYsMTAsNCwxMHogTTI4LDE0SDRjLTEuMTA0LDAtMiwwLjg5Ni0yLDIgIHMwLjg5NiwyLDIsMmgyNGMxLjEwNCwwLDItMC44OTYsMi0yUzI5LjEwNCwxNCwyOCwxNHogTTI4LDIySDRjLTEuMTA0LDAtMiwwLjg5Ni0yLDJzMC44OTYsMiwyLDJoMjRjMS4xMDQsMCwyLTAuODk2LDItMiAgUzI5LjEwNCwyMiwyOCwyMnoiIHN0eWxlPSJmaWxsOiNmZmY7Ii8+PC9zdmc+Cg==> </span><td style=vertical-align:top;>⬅ Menu: <i> <b> All </b> </i> the pages <br> quick links ⬇</table><ul class=glossymenu><li class=current><a href=. rel=nofollow> <b> Fundamentals </b> </a><li><a href=regex-disambiguation.html rel=nofollow> <b> Black Belt Program </b> </a><li><a href=regex-tricks.html rel=nofollow> <b> Regex in Action </b> </a><li><a href=regex-humor.html rel=nofollow> <b> Humor & More </b> </a><li><a href=regex-consultant.html rel=nofollow> <b> Ask Rex </b> </a></ul></nav><div class=wrap_3cols><div class=wrap_2leftcols><article "javascript:void(0)" id=the_article onclick=close_left_menu()><br><h1>Quick-Start: Regex Cheat Sheet</h1><div class=cinter><a href=http://www.copyscape.com/ rel=nofollow target=_blank> <img alt="Page copy protected against web site content
        infringement by Copyscape"title="Do not copy content from the page.
        Plagiarism will be detected by Copyscape."height=16 src=http://b.yu8.us/copyscape-white.gif width=234> </a></div><br><script>function open_left_menu() {
  document.getElementById("the_leftmenu").style.width = "33%"; 
  /* document.getElementById("the_leftmenu").style.margin = "0 67% 0 0"; */ 
}

/* Set the width of the side navigation to 0 and the left margin of the page content to 0 */
function close_left_menu() {
     var close_button = document.getElementById("mobile_close_button");
     if (window.getComputedStyle(close_button).display !== "none") {
        document.getElementById("the_leftmenu").style.width = "0";
        document.getElementById("the_article").style.marginLeft = "0";
        document.getElementById("the_banner").style.marginLeft = "0";
        document.getElementById("the_top_nav").style.marginLeft = "0";
      }
}</script> The tables below are a reference to basic regex. While reading the rest of the site, when in doubt, you can always come back and look here. (It you want a bookmark, here's a direct link to the <a href=http://www.rexegg.com/regex-quickstart.html#ref target=_blank> regex reference tables </a> ). I encourage you to print the tables so you have a cheat sheet on your desk for quick reference. <br><br> The tables are not exhaustive, for two reasons. First, every regex flavor is different, and I didn't want to crowd the page with overly exotic syntax. For a full reference to the particular regex flavors you'll be using, it's always best to go straight to the source. In fact, for some regex engines (such as Perl, PCRE, Java and .NET) you may want to check once a year, as their creators often introduce new features. <br><br> The other reason the tables are not exhaustive is that I wanted them to serve as a quick introduction to regex. If you are a complete beginner, you should get a firm grasp of basic regex syntax just by reading the examples in the tables. I tried to introduce features in a logical order and to keep out oddities that I've never seen in actual use, such as the "bell character". With these tables as a jumping board, you will be able to advance to mastery by exploring the other pages on the site. <br><br><h2>How to use the tables</h2> The tables are meant to serve as an accelerated regex course, and they are meant to be read slowly, one line at a time. On each line, in the leftmost column, you will find a new element of regex syntax. The next column, "Legend", explains what the element means (or encodes) in the regex syntax. The next two columns work hand in hand: the "Example" column gives a valid regular expression that uses the element, and the "Sample Match" column presents a text string that could be matched by the regular expression. <br><br> You can read the tables online, of course, but if you suffer from even the mildest case of online-ADD (attention deficit disorder), like most of us… Well then, I highly recommend you print them out. You'll be able to study them slowly, and to use them as a cheat sheet later, when you are reading the rest of the site or experimenting with your own regular expressions. <br><br> Enjoy! <br><br> If you overdose, make sure not to miss the next page, which comes back down to Earth and talks about some really cool stuff: <a href=regex-uses.html> <b> The 1001 ways to use Regex </b> </a> . <br><br><br><a id=ref> </a><h2>Regex Accelerated Course and Cheat Sheet</h2> For easy navigation, here are some jumping points to various sections of the page: <br><br> ✽ <a href=#chars> Characters </a><br> ✽ <a href=#quantifiers> Quantifiers </a><br> ✽ <a href=#morechars> More Characters </a><br> ✽ <a href=#logic> Logic </a><br> ✽ <a href=#whitespace> More White-Space </a><br> ✽ <a href=#morequants> More Quantifiers </a><br> ✽ <a href=#classes> Character Classes </a><br> ✽ <a href=#anchors> Anchors and Boundaries </a><br> ✽ <a href=#posix> POSIX Classes </a><br> ✽ <a href=#modifiers> Inline Modifiers </a><br> ✽ <a href=#lookarounds> Lookarounds </a><br> ✽ <a href=#classoperations> Character Class Operations </a><br> ✽ <a href=#other> Other Syntax </a><br><br><br><a id=chars> </a><span class=em8> <a href=#chars> (direct link) </a> </span><br><h2>Characters</h2><table " border=0 style=table-layout:fixed;><tbody><tr><th class=w100 scope=col>Character<th class=w200 scope=col>Legend<th class=w150 scope=col>Example<th class=w150 scope=col>Sample Match<tr class=brown><td><span class=mono> \d </span><td>Most engines: one digit <br> from 0 to 9<td>file_\d\d<td>file_25<tr class=beige><td><span class=mono> \d </span><td>.NET, Python 3: one Unicode digit in any script<td>file_\d\d<td>file_9੩<tr class=brown><td><span class=mono> \w </span><td>Most engines: "word character": ASCII letter, digit or underscore<td>\w-\w\w\w<td>A-b_1<tr class=beige><td><span class=mono> \w </span><td>.Python 3: "word character": Unicode letter, ideogram, digit, or underscore<td>\w-\w\w\w<td>字-ま_۳<tr class=brown><td><span class=mono> \w </span><td>.NET: "word character": Unicode letter, ideogram, digit, or connector<td>\w-\w\w\w<td>字-ま‿۳<tr class=beige><td><span class=mono> \s </span><td>Most engines: "whitespace character": space, tab, newline, carriage return, vertical tab<td>a\sb\sc<td>a b <br> c<tr class=brown><td><span class=mono> \s </span><td>.NET, Python 3, JavaScript: "whitespace character": any Unicode separator<td>a\sb\sc<td>a b <br> c<tr class=beige><td><span class=mono> \D </span><td>One character that is not a <i> digit </i> as defined by your engine's <i> \d </i><td>\D\D\D<td>ABC<tr class=brown><td><span class=mono> \W </span><td>One character that is not a <i> word character </i> as defined by your engine's <i> \w </i><td>\W\W\W\W\W<td>*-+=)<tr class=beige><td><span class=mono> \S </span><td>One character that is not a <i> whitespace character </i> as defined by your engine's <i> \s </i><td>\S\S\S\S<td>Yoyo</table><br><br><a id=quantifiers> </a><span class=em8> <a href=#quantifiers> (direct link) </a> </span><br><h2>Quantifiers</h2><table " border=0 style=table-layout:fixed;><tbody><tr><th class=w100 scope=col>Quantifier<th class=w200 scope=col>Legend<th class=w150 scope=col>Example<th class=w150 scope=col>Sample Match<tr class=wasabi><td><span class=mono> + </span><td>One or more<td>Version \w-\w+<td>Version A-b1_1<tr class=greentea><td><span class=mono> {3} </span><td>Exactly three times<td>\D{3}<td>ABC<tr class=wasabi><td><span class=mono> {2,4} </span><td>Two to four times<td>\d{2,4}<td>156<tr class=greentea><td><span class=mono> {3,} </span><td>Three or more times<td>\w{3,}<td>regex_tutorial<tr class=wasabi><td><span class=mono> * </span><td>Zero or more times<td>A*B*C*<td>AAACC<tr class=greentea><td><span class=mono> ? </span><td>Once or none<td>plurals?<td>plural</table><br><br><a id=morechars> </a><span class=em8> <a href=#morechars> (direct link) </a> </span><br><h2>More Characters</h2><table " border=0 style=table-layout:fixed;><tbody><tr><th class=w100 scope=col>Character<th class=w200 scope=col>Legend<th class=w150 scope=col>Example<th class=w150 scope=col>Sample Match<tr class=brown><td><span class=mono> <b> . </b> </span><td>Any character except line break<td>a.c<td>abc<tr class=beige><td><span class=mono> <b> . </b> </span><td>Any character except line break<td>.*<td>whatever, man.<tr class=brown><td><span class=mono> \ <b> . </b> </span><td>A period (special character: needs to be escaped by a \)<td>a\.c<td>a.c<tr class=beige><td><span class=mono> \ </span><td>Escapes a special character<td>\.\*\+\?    \$\^\/\\<td>.*+?    $^/\<tr class=brown><td><span class=mono> \ </span><td>Escapes a special character<td>\[\{\(\)\}\]<td>[{()}]</table><br><br><a id=logic> </a><span class=em8> <a href=#logic> (direct link) </a> </span><br><h2>Logic</h2><table " border=0 style=table-layout:fixed;><tbody><tr><th class=w100 scope=col>Logic<th class=w200 scope=col>Legend<th class=w150 scope=col>Example<th class=w150 scope=col>Sample Match<tr class=wasabi><td><span class=mono> | </span><td>Alternation / OR operand<td>22|33<td>33<tr class=greentea><td><span class=mono> ( … ) </span><td>Capturing group<td>A(nt|pple)<td>Apple (captures "pple")<tr class=wasabi><td><span class=mono> \1 </span><td>Contents of Group 1<td>r(\w)g\1x<td>regex<tr class=greentea><td><span class=mono> \2 </span><td>Contents of Group 2<td>(\d\d)\+(\d\d)=\2\+\1<td>12+65=65+12<tr class=wasabi><td><span class=mono> (?: … ) </span><td>Non-capturing group<td>A(?:nt|pple)<td>Apple</table><br><br><a id=whitespace> </a><span class=em8> <a href=#whitespace> (direct link) </a> </span><br><h2>More White-Space</h2><table " border=0 style=table-layout:fixed;><tbody><tr><th class=w100 scope=col>Character<th class=w200 scope=col>Legend<th class=w150 scope=col>Example<th class=w150 scope=col>Sample Match<tr class=brown><td><span class=mono> \t </span><td>Tab<td>T\t\w{2}<td>T     ab<tr class=beige><td><span class=mono> \r </span><td>Carriage return character<td>see below<td><tr class=brown><td><span class=mono> \n </span><td>Line feed character<td>see below<td><tr class=beige><td><span class=mono> \r\n </span><td>Line separator on Windows<td>AB\r\nCD<td>AB <br> CD<tr class=brown><td><span class=mono> \N </span><td>Perl, PCRE (C, PHP, R…): one character that is not a line break<td>\N+<td>ABC<tr class=beige><td><span class=mono> \h </span><td>Perl, PCRE (C, PHP, R…), Java: one horizontal whitespace character: tab or Unicode space separator<td><td><tr class=brown><td><span class=mono> \H </span><td>One character that is not a horizontal whitespace<td><td><tr class=beige><td><span class=mono> \v </span><td>.NET, JavaScript, Python, Ruby: vertical tab<td><td><tr class=brown><td><span class=mono> \v </span><td>Perl, PCRE (C, PHP, R…), Java: one vertical whitespace character: line feed, carriage return, vertical tab, form feed, paragraph or line separator<td><td><tr class=beige><td><span class=mono> \V </span><td>Perl, PCRE (C, PHP, R…), Java: any character that is not a vertical whitespace<td><td><tr class=brown><td><span class=mono> \R </span><td>Perl, PCRE (C, PHP, R…), Java: one line break (carriage return + line feed pair, and all the characters matched by \v)<td><td></table><br><br><a id=morequants> </a><span class=em8> <a href=#morequants> (direct link) </a> </span><br><h2>More Quantifiers</h2><table " border=0 style=table-layout:fixed;><tbody><tr><th class=w100 scope=col>Quantifier<th class=w200 scope=col>Legend<th class=w150 scope=col>Example<th class=w150 scope=col>Sample Match<tr class=wasabi><td><span class=mono> + </span><td>The + (one or more) is "greedy"<td>\d+<td>12345<tr class=greentea><td><span class=mono> ? </span><td>Makes quantifiers "lazy"<td>\d+?<td>1 in <b> 1 </b> 2345<tr class=wasabi><td><span class=mono> * </span><td>The * (zero or more) is "greedy"<td>A*<td>AAA<tr class=greentea><td><span class=mono> ? </span><td>Makes quantifiers "lazy"<td>A*?<td>empty in AAA<tr class=wasabi><td><span class=mono> {2,4} </span><td>Two to four times, "greedy"<td>\w{2,4}<td>abcd<tr class=greentea><td><span class=mono> ? </span><td>Makes quantifiers "lazy"<td>\w{2,4}?<td>ab in <b> ab </b> cd</table><br><br><a id=classes> </a><span class=em8> <a href=#classes> (direct link) </a> </span><br><h2>Character Classes</h2><table " border=0 style=table-layout:fixed;><tbody><tr><th class=w100 scope=col>Character<th class=w200 scope=col>Legend<th class=w150 scope=col>Example<th class=w150 scope=col>Sample Match<tr class=brown><td><span class=mono> [ … ] </span><td>One of the characters in the brackets<td>[AEIOU]<td>One uppercase vowel<tr class=beige><td><span class=mono> [ … ] </span><td>One of the characters in the brackets<td>T[ao]p<td><i> Tap </i> or <i> Top </i><tr class=brown><td><span class=mono> - </span><td>Range indicator<td>[a-z]<td>One lowercase letter<tr class=beige><td><span class=mono> [x-y] </span><td>One of the characters in the range from x to y<td>[A-Z]+<td>GREAT<tr class=brown><td><span class=mono> [ … ] </span><td>One of the characters in the brackets<td>[AB1-5w-z]<td>One of either: A,B,1,2,3,4,5,w,x,y,z<tr class=beige><td><span class=mono> [x-y] </span><td>One of the characters in the range from x to y<td>[ -~]+<td>Characters in the printable section of the <a href=http://www.asciitable.com/ target=_blank> ASCII table </a> .<tr class=brown><td><span class=mono> [^x] </span><td>One character that is not x<td>[^a-z]{3}<td>A1!<tr class=beige><td><span class=mono> [^x-y] </span><td>One of the characters <b> not </b> in the range from x to y<td>[^ -~]+<td>Characters that are <b> not </b> in the printable section of the <a href=http://www.asciitable.com/ target=_blank> ASCII table </a> .<tr class=brown><td><span class=mono> [\d\D] </span><td>One character that is a digit or a non-digit<td>[\d\D]+<td>Any characters, inc- <br> luding new lines, which the regular dot doesn't match<tr class=beige><td><span class=mono> [\x41] </span><td>Matches the character at hexadecimal position 41 in the ASCII table, i.e. A<td>[\x41-\x45]{3}<td>ABE</table><br><br><a id=anchors> </a><span class=em8> <a href=#anchors> (direct link) </a> </span><br><h2><a href=regex-anchors.html> Anchors </a> and <a href=regex-boundaries.html> Boundaries </a></h2><table " border=0 style=table-layout:fixed;><tbody><tr><th class=w100 scope=col>Anchor<th class=w200 scope=col>Legend<th class=w150 scope=col>Example<th class=w150 scope=col>Sample Match<tr class=wasabi><td><span class=mono> ^ </span><td><a href=regex-anchors.html#caret> Start of string </a> or <a href=regex-anchors.html#carmulti> start of line </a> depending on multiline mode. (But when [^inside brackets], it means "not")<td>^abc .*<td>abc (line start)<tr class=greentea><td><span class=mono> $ </span><td><a href=regex-anchors.html#dollar> End of string </a> or <a href=regex-anchors.html#eol> end of line </a> depending on multiline mode. Many engine-dependent subtleties.<td>.*? the end$<td>this is the end<tr class=wasabi><td><span class=mono> \A </span><td><a href=regex-anchors.html#A> Beginning of string </a> <br> (all major engines except JS)<td>\Aabc[\d\D]*<td>abc (string... <br> ...start)<tr class=greentea><td><span class=mono> \z </span><td><a href=regex-anchors.html#z> Very end of the string </a> <br> Not available in Python and JS<td>the end\z<td>this is...\n... <b> the end </b><tr class=wasabi><td><span class=mono> \Z </span><td><a href=regex-anchors.html#Z> End of string </a> or (except Python) before final line break <br> Not available in JS<td>the end\Z<td>this is...\n... <b> the end </b> \n<tr class=greentea><td><span class=mono> \G </span><td><a href=regex-anchors.html#G> Beginning of String or End of Previous Match </a> <br> .NET, Java, PCRE (C, PHP, R…), Perl, Ruby<td><td><tr class=wasabi><td><span class=mono> \b </span><td><a href=regex-boundaries.html#wordboundary> Word boundary </a> <br> Most engines: position where one side only is an ASCII letter, digit or underscore<td>Bob.*\bcat\b<td>Bob ate the cat<tr class=greentea><td><span class=mono> \b </span><td><a href=regex-boundaries.html#wordboundary> Word boundary </a> <br> .NET, Java, Python 3, Ruby: position where one side only is a Unicode letter, digit or underscore<td>Bob.*\b\кошка\b<td>Bob ate the кошка<tr class=wasabi><td><span class=mono> \B </span><td><a href=regex-boundaries.html#notb> Not a word boundary </a><td>c.*\Bcat\B.*<td>copycats</table><br><br><a id=posix> </a><span class=em8> <a href=#posix> (direct link) </a> </span><br><h2>POSIX Classes</h2><table " border=0 style=table-layout:fixed;><tbody><tr><th class=w100 scope=col>Character<th class=w200 scope=col>Legend<th class=w150 scope=col>Example<th class=w150 scope=col>Sample Match<tr class=brown><td><span class=mono> [:alpha:] </span><td>PCRE (C, PHP, R…): ASCII letters A-Z and a-z<td>[8[:alpha:]]+<td>WellDone88<tr class=beige><td><span class=mono> [:alpha:] </span><td>Ruby 2: Unicode letter or ideogram<td>[[:alpha:]\d]+<td>кошка99<tr class=brown><td><span class=mono> [:alnum:] </span><td>PCRE (C, PHP, R…): ASCII digits and letters A-Z and a-z<td>[[:alnum:]]{10}<td>ABCDE12345<tr class=beige><td><span class=mono> [:alnum:] </span><td>Ruby 2: Unicode digit, letter or ideogram<td>[[:alnum:]]{10}<td>кошка90210<tr class=brown><td><span class=mono> [:punct:] </span><td>PCRE (C, PHP, R…): ASCII punctuation mark<td>[[:punct:]]+<td>?!.,:;<tr class=beige><td><span class=mono> [:punct:] </span><td>Ruby: Unicode punctuation mark<td>[[:punct:]]+<td>‽,:〽⁆</table><br><br><a id=modifiers> </a><span class=em8> <a href=#modifiers> (direct link) </a> </span><br><h2><a href=regex-modifiers.html> Inline Modifiers </a></h2> None of these are supported in JavaScript. In Ruby, beware of <span class=socode> (?s) </span> and <span class=socode> (?m) </span> . <br><table " border=0 style=table-layout:fixed;><tbody><tr><th class=w100 scope=col>Modifier<th class=w200 scope=col>Legend<th class=w150 scope=col>Example<th class=w150 scope=col>Sample Match<tr class=wasabi><td><span class=mono> (?i) </span><td><a href=regex-modifiers.html#i> Case-insensitive mode </a> <br> (except JavaScript)<td>(?i)Monday<td>monDAY<tr class=greentea><td><span class=mono> (?s) </span><td><a href=regex-modifiers.html#dotall> DOTALL mode </a> (except JS and Ruby). The dot (.) matches new line characters (\r\n). Also known as "single-line mode" because the dot treats the entire input as a single line<td>(?s)From A.*to Z<td>From A <br> to Z<tr class=wasabi><td><span class=mono> (?m) </span><td><a href=regex-modifiers.html#multiline> Multiline mode </a> <br> (except Ruby and JS) ^ and $ match at the beginning and end of every line<td>(?m)1\r\n^2$\r\n^3$<td>1 <br> 2 <br> 3<tr class=greentea><td><span class=mono> (?m) </span><td><a href=regex-modifiers.html#rubym> In Ruby </a> : the same as (?s) in other engines, i.e. DOTALL mode, i.e. dot matches line breaks<td>(?m)From A.*to Z<td>From A <br> to Z<tr class=wasabi><td><span class=mono> (?x) </span><td><a href=regex-modifiers.html#freespacing> Free-Spacing Mode mode </a> <br> (except JavaScript). Also known as comment mode or whitespace mode<td>(?x) # this is a <br> # comment <br> abc # write on multiple <br> # lines <br> [ ]d # spaces must be <br> # in brackets<td>abc d<tr class=greentea><td><span class=mono> (?n) </span><td><a href=regex-modifiers.html#n> .NET, PCRE 10.30+: named capture only </a><td>Turns all (parentheses) into non-capture groups. To capture, use <a href=regex-capture.html#namedgroups> named groups </a> .<td><tr class=wasabi><td><span class=mono> (?d) </span><td><a href=regex-modifiers.html#d> Java: Unix linebreaks only </a><td>The dot and the ^ and $ anchors are only affected by \n<td><tr class=greentea><td><span class=mono> (?^) </span><td><a href=regex-disambiguation.html#unset-all> PCRE 10.32+: unset modifiers </a><td>Unsets <span class=mono> ismnx </span> modifiers<td></table><br><br><a id=lookarounds> </a><span class=em8> <a href=#lookarounds> (direct link) </a> </span><br><h2><a href=regex-lookarounds.html> Lookarounds </a></h2><table " border=0 style=table-layout:fixed;><tbody><tr><th class=w100 scope=col>Lookaround<th class=w200 scope=col>Legend<th class=w150 scope=col>Example<th class=w150 scope=col>Sample Match<tr class=brown><td><span class=mono> (?=…) </span><td><a href=regex-disambiguation.html#lookahead> Positive lookahead </a><td>(?=\d{10})\d{5}<td>01234 in <b> 01234 </b> 56789<tr class=beige><td><span class=mono> (?<=…) </span><td><a href=regex-disambiguation.html#lookbehind> Positive lookbehind </a><td>(?<=\d)cat<td>cat in 1 <b> cat </b><tr class=brown><td><span class=mono> (?!…) </span><td><a href=regex-disambiguation.html#negative-lookahead> Negative lookahead </a><td>(?!theatre)the\w+<td>theme<tr class=beige><td><span class=mono> (?&LT!…) </span><td><a href=regex-disambiguation.html#negative-lookbehind> Negative lookbehind </a><td>\w{3}(?&LT!mon)ster<td>Munster</table><br><br><a id=classoperations> </a><span class=em8> <a href=#classoperations> (direct link) </a> </span><br><h2><a href=regex-class-operations.html> Character Class Operations </a></h2><table " border=0 style=table-layout:fixed;><tbody><tr><th class=w100 scope=col>Class Operation<th class=w200 scope=col>Legend<th class=w150 scope=col>Example<th class=w150 scope=col>Sample Match<tr class=wasabi><td><span class=mono> […-[…]] </span><td>.NET: character class subtraction. One character that is in those on the left, but not in the subtracted class.<td>[a-z-[aeiou]]<td>Any lowercase consonant<tr class=greentea><td><span class=mono> […-[…]] </span><td>.NET: character class subtraction.<td>[\p{IsArabic}-[\D]]<td>An Arabic character that is not a non-digit, i.e., an Arabic digit<tr class=wasabi><td><span class=mono> […&&[…]] </span><td>Java, Ruby 2+: character class intersection. One character that is both in those on the left and in the && class.<td>[\S&&[\D]]<td>An non-whitespace character that is a non-digit.<tr class=greentea><td><span class=mono> […&&[…]] </span><td>Java, Ruby 2+: character class intersection.<td>[\S&&[\D]&&[^a-zA-Z]]<td>An non-whitespace character that a non-digit and not a letter.<tr class=wasabi><td><span class=mono> […&&[^…]] </span><td>Java, Ruby 2+: character class subtraction is obtained by intersecting a class with a negated class<td>[a-z&&[^aeiou]]<td>An English lowercase letter that is not a vowel.<tr class=greentea><td><span class=mono> […&&[^…]] </span><td>Java, Ruby 2+: character class subtraction<td>[\p{InArabic}&&[^\p{L}\p{N}]]<td>An Arabic character that is not a letter or a number</table><br><br><a id=other> </a><span class=em8> <a href=#other> (direct link) </a> </span><br><h2>Other Syntax</h2><table " border=0 style=table-layout:fixed;><tbody><tr><th class=w100 scope=col>Syntax<th class=w200 scope=col>Legend<th class=w150 scope=col>Example<th class=w150 scope=col>Sample Match<tr class=brown><td><name ="k"> <span class=mono> \K </span> </name><td><a href=regex-best-trick.html#bsk> Keep Out </a> <br> Perl, PCRE (C, PHP, R…), Python's alternate <a href=https://pypi.python.org/pypi/regex target=_blank> <i> regex </i> </a> engine, Ruby 2+: drop everything that was matched so far from the overall match to be returned<td>prefix\K\d+<td>12<tr class=beige><td><name ="blockescape"> <span class=mono> \Q…\E </span> </name><td>Perl, PCRE (C, PHP, R…), Java: treat anything between the delimiters as a literal string. Useful to escape metacharacters.<td>\Q(C++ ?)\E<td>(C++ ?)</table><br><br><br><br><div class=cinter>Don't Miss The <a href=regex-style.html> <span class="redtext em2"> <b> Regex Style Guide </b> </span> </a><br><br> and <a href=regex-best-trick.html> <span class="redtext em2"> <b> The Best Regex Trick Ever!!! </b> </span> </a><br></div><a href=regex-uses.html> <img alt=next class=left height=40 src=http://b.yu8.us/next_regex.png width=125> <br> <b>  The 1001 ways to use Regex </b> </a><br><br><br><div class=cinter><a href=regex-consultant.html> <img alt="Regex Rex"class=tada height=100 src=http://b.yu8.us/rightgraphic_rexegg3.png width=100> <br> <b> Ask Rex </b> </a><br><br></div><a id=comlist> </a><div class=comment-wrapper><br><div class=cinter><a href=#comform> Leave a Comment </a></div><div class="cinter redtext mt1">1-10 of 18 Threads</div><a id=cid3106> </a><div class=comment><div class=comment-header><div class=comment-author_location><span class=comment-author> maureen </span><span class=comment-location> – san francisco </span></div><div class=comment-date>June 18, 2021 - 16:25</div></div><div class=comment-subject><span class=comment-subject-title> Subject: </span> absolutely the BEST website for regex</div><br><div class=comment-text>This is the go-to website for everything on regex. Thank you!</div></div><a id=cid2825> </a><div class=comment><div class=comment-header><div class=comment-author_location><span class=comment-author> Pythia </span><span class=comment-location> – New Zealand </span></div><div class=comment-date>July 15, 2020 - 03:54</div></div><div class=comment-subject><span class=comment-subject-title> Subject: </span> Very thoughtful and useful cheat sheet</div><br><div class=comment-text>Unlike lots of other cheat sheets or regex web sites, I was able (without much persistent regex knowledge) to apply the rules and to solve my problem. THANK YOU :)</div></div><a id=cid2815> </a><div class=comment><div class=comment-header><div class=comment-author_location><span class=comment-author> Mark </span></div><div class=comment-date>July 04, 2020 - 10:14</div></div><div class=comment-subject><span class=comment-subject-title> Subject: </span> Thanks a lot</div><br><div class=comment-text>Thanks a lot for the quick guide. It's really helpful.</div></div><a id=cid2805> </a><div class=comment><div class=comment-header><div class=comment-author_location><span class=comment-author> Purusharth Amrut </span></div><div class=comment-date>June 10, 2020 - 14:41</div></div><div class=comment-subject><span class=comment-subject-title> Subject: </span> Very useful site</div><br><div class=comment-text>Thank you soooooo much for this site. I'm using python regex for natural language processing in sentiment analysis and this helped me a lot.</div></div><a id=cid2762> </a><div class=comment><div class=comment-header><div class=comment-author_location><span class=comment-author> Alessandro Maiorana </span><span class=comment-location> – Italy, Milan </span></div><div class=comment-date>April 15, 2020 - 12:43</div></div><div class=comment-subject><span class=comment-subject-title> Subject: </span> Thank you! Excellent resource for any student</div><br><div class=comment-text>Thank you so much for this incredible cheatsheet! It is facilitating a lot my regex learning! God bless you and your passion!</div></div><a id=cid2753> </a><div class=comment><div class=comment-header><div class=comment-author_location><span class=comment-author> michael </span><span class=comment-location> – Bulgaria </span></div><div class=comment-date>April 10, 2020 - 12:43</div></div><div class=comment-subject><span class=comment-subject-title> Subject: </span> Thank you for doing such a geat work.</div><br><div class=comment-text>I am now learning regex and for finding such a well organized site is a blessing! You are a good soul! Thank you for everything and stay inspired!</div></div><a id=cid2702> </a><div class=comment><div class=comment-header><div class=comment-author_location><span class=comment-author> Yuri </span><span class=comment-location> – California </span></div><div class=comment-date>November 13, 2019 - 17:39</div></div><div class=comment-subject><span class=comment-subject-title> Subject: </span> Simple = perfect</div><br><div class=comment-text>Thanks a lot, saved me tons of time!!!!</div></div><a id=cid2678> </a><div class=comment><div class=comment-header><div class=comment-author_location><span class=comment-author> Tom </span><span class=comment-location> – Europe, Poland </span></div><div class=comment-date>September 30, 2019 - 18:43</div></div><div class=comment-subject><span class=comment-subject-title> Subject: </span> Congratulations</div><br><div class=comment-text>Well done, very useful page. Thank you for your effort. T</div></div><a id=cid2611> </a><div class=comment><div class=comment-header><div class=comment-author_location><span class=comment-author> Najam </span></div><div class=comment-date>March 25, 2019 - 03:44</div></div><div class=comment-subject><span class=comment-subject-title> Subject: </span> Thank you very much</div><br><div class=comment-text>Hi Rex, <br><br> Thankyou very much for compiling these. I am new to text analytics and is struggling a lot with regex. This is helping me a lot pick up. Great work</div></div><a id=cid2413> </a><div class=comment><div class=comment-header><div class=comment-author_location><span class=comment-author> Philip </span><span class=comment-location> – Shannon, Ireland </span></div><div class=comment-date>September 28, 2017 - 15:57</div></div><div class=comment-subject><span class=comment-subject-title> Subject: </span> Nice summary</div><br><div class=comment-text>Nice summary of regex. I was trying to remember how to group and I found the example above. Thanks.</div></div><br><div class=cinter><a href=?cp=2#comlist rel=nofollow> <img alt=Next height=16 src=http://a.yu8.us/nav_next16.png width=16> </a>   </div></div><br><br><a id=comform> </a><div class=comment-form-wrapper><div class="cinter redtext mt1">Leave a Comment</div><div id=comment-form-div><form action=regex-quickstart.html method=post><input name=token type=hidden value=acd3db018855416aa4f33f6ed89a335e><input name=admin type=hidden value=0><input class=comment-field name=poster><label class=comment-required-field>*</label><label class=comment-label>Your name</label><br><input class=comment-field name=email><label class=comment-required-field>*</label><label class=comment-label>Email (it will not be shown)</label><br><input class=comment-field name=location><label class=comment-label>Your location</label><br><br><label class=comment-label>Subject:</label><input class=comment-subject-field maxlength=128 name=subject><br><br><div class="cinter blue"><b> All comments are moderated. <br> Link spammers, this won't work for you. </b></div><textarea name=comment></textarea><br> To prevent automatic spam, may I gently ask that you go through these crazy hoops… <br><div class=captcha_wrapper><div class=g-recaptcha data-sitekey=6Lc2WE8UAAAAABFS5ks4OB6onjL6EJOP_kDE7zTZ></div></div><div id=comment-form-submit-line><input class=comment-submit name=submitcomment onmouseout=this.className='comment-submit' onmouseover=this.className='comment-submit-hover' type=submit value=Submit></div></form></div></div><br></article><nav class="leftmenu fadein"id=the_leftmenu><a class="mobile_only mob_leftmenu_close_button"href=javascript:void(0) id=mobile_close_button onclick=close_left_menu()> × </a><b> Fundamentals </b><br><ul><li><a href=.> Regex Tutorial </a><li><a href=regex-vs-regular-expression.html> Regex vs. Regex </a><li><a class=thispage href=regex-quickstart.html> Quick Reference </a><li><a href=regex-uses.html> 100 Uses for Regex </a><li><a href=regex-style.html> Regex Style Guide </a></ul><br><b> Black Belt Program </b><br><ul><li><a href=regex-disambiguation.html> All <span class=mono> (? … ) Syntax </span> </a><li><a href=regex-boundaries.html> Boundaries++ </a><li><a href=regex-anchors.html> Anchors </a><li><a href=regex-capture.html> Capture & Back </a><li><a href=regex-modifiers.html> Flags & Modifiers </a><li><a href=regex-lookarounds.html> Lookarounds </a><li><a href=regex-quantifiers.html> Quantifiers </a><li><a href=regex-explosive-quantifiers.html> Explosive Quantifiers </a><li><a href=regex-conditionals.html> Conditionals </a><li><a href=regex-recursion.html> Recursion </a><li><a href=regex-class-operations.html> Class Operations </a><li><a href=backtracking-control-verbs.html> Backtracking Control </a><li><a href=regex-gotchas.html> Regex <i> Gotchas </i> </a><li><a href=regex-tricks.html> Syntax Tricks </a><li><a href=pcre-callouts.html> PCRE Callouts </a><li><a href=regex-quantifier-capture.html> Quantifier capture </a></ul><br><b> Regex in Action </b><br><div>For awesome tricks: <br> scroll down!</div><ul><li><a href=regex-cookbook.html> Cookbook </a><li><a href=regex-interesting-character-classes.html> Cool Regex Classes </a><li><a href=regex-optimizations.html> Regex Optimizations </a><li><a href=pcregrep-pcretest.html> PCRE: Grep and Test </a><li><a href=regex-perl-one-liners.html> Perl One-Liners </a><li><a href=regex-firefox-shortcuts.html> Amazing Shortcuts </a></ul><br><b> Tools & More </b><br><ul><li><a href=regex-tools.html> Regex Tools </a><li><a href=regexbuddy-tutorial.html> RegexBuddy </a><li><a href=regex-humor.html> Regex Humor </a><li><a href=regex-books.html> Regex Books & Links </a></ul><br><b> Tricks </b><br><ul><li><a href=regex-best-trick.html> The Best Regex Trick </a><li><a href=regex-trick-conditional-replacement.html> Conditional Sub </a><li><a href=regex-trick-line-numbers.html> Line Numbers </a><li><a href=regex-trick-numbers-in-english.html> Numbers in English </a></ul><br><b> Languages </b><br><ul><li><a href=pcre-documentation.html> PCRE Doc & Log </a><li><a href=regex-perl.html> Regex with Perl </a><li><a href=regex-csharp.html> Regex with C# </a><li><a href=regex-php.html> Regex with PHP </a><li><a href=regex-python.html> Regex with Python </a><li><a href=regex-java.html> Regex with Java </a><li><a href=regex-javascript.html> Regex with JavaScript </a><li><a href=regex-ruby.html> Regex with Ruby </a><li><a href=regex-vbnet.html> Regex with VB.NET </a></ul><br></nav></div></div><div class="topanchor desktop_only"><aside class="rightcolumn fadein"><table class=cintable><tbody><tr><td style=text-align:center;><a href=http://www.amazon.com/dp/0596528124?tag=onamazon-20 rel=nofollow target=_blank> <img alt="Matering Regular Expressions"class=pulse1st height=160 src=http://a.yu8.us/c_mastering-regex.jpg width=116> <br> <span class="greytext em9"> <b> A must-read </b> </span> <br> <br> </a></table><div class="cinter greytext"><b> RegexBuddy 4 is <br> the <i> best </i> regex tool! <br> </b><div class="em9 pulse2nd strong"><a href=regexbuddy-trial.html> <span class="redtext under"> Get the Free Trial </span> </a><br><a href=regexbuddy-tutorial.html> <span class="redtext under"> Huge RB Tutorial </span> </a></div><br><div style="margin: 0 0 -0.5em 0;"class=dtada><img alt="Regex Rex"class=tada height=100 src=http://b.yu8.us/rightgraphic_rexegg3.png width=100></div><span class="greytext em9"> <a href=regex-consultant.html> <b> Ask Rex </b> </a> </span><br><form action=http://www.google.com/search target=_blank><input placeholder="search the site"class=searchbox maxlength=255 name=q size=14><input name=sitesearch type=hidden value=RexEgg.com><input alt=Search src=http://b.yu8.us/search2.png title=Search type=image></form></div><br></aside></div><footer><br><b> © Copyright RexEgg.com </b><br><br><br><br><br><br><br></footer>