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

/
/
gs

Test String

Code Generator

Generated Code

use strict; my $str = '<div class="menu"> <div class="innermenu pagewidth"> <div class="leftside"></div> <ul> <li class="parent" > <h3> <a href="#" title="Menu" id="headlink4" class="spanhover mainlevel"> <span>Menu</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> <div class="submenu level1"> <ul class="level1"> <li class="parent" id="hcategory_1"> <h3> <a href="pl/c/Szyby-nowe/1.html" title="Szyby nowe" id="headercategory1" class="spanhover"> <span>Szyby nowe</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> <div class="submenu level2"> <ul class="level2"> <li class="" id="hcategory_7"> <h3> <a href="pl/c/ACURA/7.html" title="ACURA" id="headercategory7" class="spanhover"> <span>ACURA</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_8"> <h3> <a href="pl/c/AUDI/8.html" title="AUDI" id="headercategory8" class="spanhover"> <span>AUDI</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_9"> <h3> <a href="pl/c/BMW/9.html" title="BMW" id="headercategory9" class="spanhover"> <span>BMW</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_40"> <h3> <a href="pl/c/BUICK/40.html" title="BUICK" id="headercategory40" class="spanhover"> <span>BUICK</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_10"> <h3> <a href="pl/c/CADILLAC/10.html" title="CADILLAC" id="headercategory10" class="spanhover"> <span>CADILLAC</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_11"> <h3> <a href="pl/c/CHEVROLET/11.html" title="CHEVROLET" id="headercategory11" class="spanhover"> <span>CHEVROLET</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_14"> <h3> <a href="pl/c/CHRYSLER/14.html" title="CHRYSLER" id="headercategory14" class="spanhover"> <span>CHRYSLER</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_46"> <h3> <a href="pl/c/CITROEN/46.html" title="CITROEN" id="headercategory46" class="spanhover"> <span>CITROEN</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_15"> <h3> <a href="pl/c/DODGE/15.html" title="DODGE" id="headercategory15" class="spanhover"> <span>DODGE</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_44"> <h3> <a href="pl/c/FIAT/44.html" title="FIAT" id="headercategory44" class="spanhover"> <span>FIAT</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_16"> <h3> <a href="pl/c/FORD/16.html" title="FORD" id="headercategory16" class="spanhover"> <span>FORD</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_12"> <h3> <a href="pl/c/GMC/12.html" title="GMC" id="headercategory12" class="spanhover"> <span>GMC</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_17"> <h3> <a href="pl/c/HONDA/17.html" title="HONDA" id="headercategory17" class="spanhover"> <span>HONDA</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_18"> <h3> <a href="pl/c/HUMMER/18.html" title="HUMMER" id="headercategory18" class="spanhover"> <span>HUMMER</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_19"> <h3> <a href="pl/c/HYUNDAI/19.html" title="HYUNDAI" id="headercategory19" class="spanhover"> <span>HYUNDAI</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_20"> <h3> <a href="pl/c/INFINITI/20.html" title="INFINITI" id="headercategory20" class="spanhover"> <span>INFINITI</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_13"> <h3> <a href="pl/c/ISUZU/13.html" title="ISUZU" id="headercategory13" class="spanhover"> <span>ISUZU</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_21"> <h3> <a href="pl/c/JAGUAR/21.html" title="JAGUAR" id="headercategory21" class="spanhover"> <span>JAGUAR</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_22"> <h3> <a href="pl/c/JEEP/22.html" title="JEEP" id="headercategory22" class="spanhover"> <span>JEEP</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_23"> <h3> <a href="pl/c/KIA/23.html" title="KIA" id="headercategory23" class="spanhover"> <span>KIA</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_45"> <h3> <a href="pl/c/LANCIA/45.html" title="LANCIA" id="headercategory45" class="spanhover"> <span>LANCIA</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_24"> <h3> <a href="pl/c/LAND-ROVER/24.html" title="LAND ROVER" id="headercategory24" class="spanhover"> <span>LAND ROVER</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_25"> <h3> <a href="pl/c/LEXUS/25.html" title="LEXUS" id="headercategory25" class="spanhover"> <span>LEXUS</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_38"> <h3> <a href="pl/c/LINCOLN/38.html" title="LINCOLN" id="headercategory38" class="spanhover"> <span>LINCOLN</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_26"> <h3> <a href="pl/c/MAZDA/26.html" title="MAZDA" id="headercategory26" class="spanhover"> <span>MAZDA</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_27"> <h3> <a href="pl/c/MERCEDES-BENZ/27.html" title="MERCEDES BENZ" id="headercategory27" class="spanhover"> <span>MERCEDES BENZ</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_48"> <h3> <a href="pl/c/MERCURY/48.html" title="MERCURY" id="headercategory48" class="spanhover"> <span>MERCURY</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_28"> <h3> <a href="pl/c/MITSUBISHI/28.html" title="MITSUBISHI" id="headercategory28" class="spanhover"> <span>MITSUBISHI</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_29"> <h3> <a href="pl/c/NISSAN/29.html" title="NISSAN" id="headercategory29" class="spanhover"> <span>NISSAN</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_41"> <h3> <a href="pl/c/OLDSMOBILE/41.html" title="OLDSMOBILE" id="headercategory41" class="spanhover"> <span>OLDSMOBILE</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_30"> <h3> <a href="pl/c/OPEL/30.html" title="OPEL" id="headercategory30" class="spanhover"> <span>OPEL</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_47"> <h3> <a href="pl/c/PEUGEOT/47.html" title="PEUGEOT" id="headercategory47" class="spanhover"> <span>PEUGEOT</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_43"> <h3> <a href="pl/c/PONTIAC/43.html" title="PONTIAC" id="headercategory43" class="spanhover"> <span>PONTIAC</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_31"> <h3> <a href="pl/c/PORSCHE/31.html" title="PORSCHE" id="headercategory31" class="spanhover"> <span>PORSCHE</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_32"> <h3> <a href="pl/c/RANGE-ROVER/32.html" title="RANGE ROVER" id="headercategory32" class="spanhover"> <span>RANGE ROVER</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_33"> <h3> <a href="pl/c/SAAB/33.html" title="SAAB" id="headercategory33" class="spanhover"> <span>SAAB</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_42"> <h3> <a href="pl/c/SATURN/42.html" title="SATURN" id="headercategory42" class="spanhover"> <span>SATURN</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_34"> <h3> <a href="pl/c/SUBARU/34.html" title="SUBARU" id="headercategory34" class="spanhover"> <span>SUBARU</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_35"> <h3> <a href="pl/c/SUZUKI/35.html" title="SUZUKI" id="headercategory35" class="spanhover"> <span>SUZUKI</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_36"> <h3> <a href="pl/c/TOYOTA/36.html" title="TOYOTA" id="headercategory36" class="spanhover"> <span>TOYOTA</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_37"> <h3> <a href="pl/c/VOLKSWAGEN/37.html" title="VOLKSWAGEN" id="headercategory37" class="spanhover"> <span>VOLKSWAGEN</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_39"> <h3> <a href="pl/c/VOLVO/39.html" title="VOLVO" id="headercategory39" class="spanhover"> <span>VOLVO</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> </ul> </div> </li> <li class="" id="hcategory_2"> <h3> <a href="pl/c/Szyby-uzywane/2.html" title="Szyby używane" id="headercategory2" class="spanhover"> <span>Szyby używane</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_3"> <h3> <a href="pl/c/Czesci-samochodowe/3.html" title="Części samochodowe" id="headercategory3" class="spanhover"> <span>Części samochodowe</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_5"> <h3> <a href="pl/c/Zabezpieczenia-do-motocykli-i-rowerow/5.html" title="Zabezpieczenia do motocykli i rowerów" id="headercategory5" class="spanhover"> <span>Zabezpieczenia do motocykli i rowerów</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" id="hcategory_4"> <h3> <a href="pl/c/Samochody/4.html" title="Samochody" id="headercategory4" class="spanhover"> <span>Samochody</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> </ul> </div> </li> <li class="" > <h3> <a href="pl/i/Regulamin/2.html" title="Regulamin" id="headlink1" class="spanhover mainlevel"> <span>Regulamin</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" > <h3> <a href="pl/contact.html" title="Formularz kontaktowy" id="headlink2" class="spanhover mainlevel"> <span>Formularz kontaktowy</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> <li class="" > <h3> <a href="pl/i/Polityka-prywatnosci/3.html" title="Polityka prywatności" id="headlink3" class="spanhover mainlevel"> <span>Polityka prywatności</span> <img src="public/images/1px.gif" alt="" class="px1" /> </a> </h3> </li> </ul> <div class="rightside"></div> </div> </div>'; my $regex = qr/(<div class="[^"]*?\menu\b[^"]*?">.*?<\/div>)/sp; if ( $str =~ /$regex/g ) { print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n"; # print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n"; # print "Capture Group 2 is $2 ... and so on\n"; } # ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p' # Named capture groups can be called via $+{name}

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 Perl, please visit: http://perldoc.perl.org/perlre.html