Regular Expressions 101

Save & Share

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

/
/
gm

Test String

Code Generator

Generated Code

# coding=utf8 # the above tag defines encoding for this document and is for Python 2.x compatibility import re regex = r">[\r\n\s]*\b([0-9a-zA-Zàè ,\s\r\n]+)\b[\s\r\n]*<" test_str = ("@extends('frontend.layout')\n\n" "@section('mainsection')\n" " <section class=\"mainsection\">\n" " <div class=\"row d-none d-lg-flex fe_row_breadcrumbs mx-0\">\n" " <div class=\"col-10 py-4 px-0 d-flex justify-content-between\">\n" " <div class=\"d-flex align-items-center justify-content-start\"><a href=\"/\"\n" " class=\"breadcrumbs_parent\">\n\n\n\n\n\n\n\n" "Home\n" "</a><span class=\"breadcrumbs_slash\"> / </span><a href=\"/chi-siamo/\"\n" " class=\"breadcrumbs_cur\">Storia</a></div>\n" " </div>\n" " </div>\n" " <div class=\"row d-flex justify-content-center row_storia my-4\">\n" " <div class=\"col-10 mb-3 d-none d-lg-flex\">\n" " <h1 class=\"fe_title1\">\n" " Chi siamo\n\n\n\n\n\n" " </h1>\n" " </div>\n" " <div class=\"col-12 col-lg-10\">\n" " <div class=\"row\">\n" " <div class=\"col-12 col-lg-6 mt-3 order-2 order-lg-1\">\n" " <p class=\"fe_text4 interlinea1 pr-0 pr-lg-5\">\n" " <strong>Fabbricatorino</strong> è una azienda storica che nasce negli anni ’20 come “Società\n" " Anonima Fabbrica Torino” specializzata nella produzione di oggetti e componenti in\n" " <strong>bachelite</strong>. Il suo avvicinamento al mondo degli occhiali fu del tutto casuale,\n" " si narra infatti che fu all’<strong>Autodromo di Monza</strong> in occasione del “Gran Premio\n" " Automobilistico d’Autunno” durante i festeggiamenti per la vittoria di <strong>Maserati\n" " Alfieri</strong> su <strong>Auto \n\n" "Diatto 3 Litri</strong>, che i fondatori di Fabbricatorino\n" " si proposero per fornire al gruppo gli “<strong>occhiali da gara</strong>” per i loro piloti.\n" " </p>\n" " </div>\n" " <div class=\"col-12 col-lg-6 mt-3 d-flex justify-content-center align-items-center order-1 order-lg-2\">\n" " <img src=\"https://www.occhialifabbricatorino.it/images/banner/it/aboutus/bg-chisiamo.jpg\"\n" " class=\"img-fluid\">\n" " </div>\n" " <div class=\"col-12 col-lg-6 mt-3 order-4 order-lg-3\">\n" " <p class=\"fe_text4 interlinea1\">\n" " Il <strong>DNA innovativo</strong> dell’azienda portò verso la fine degli anni ‘30 alla\n" " sperimentazione di <strong>nuovi materiali</strong> primo fra tutti l’<strong>acetato</strong>,\n" " recente scoperta di un chimico belga, destinato negli anni a venire a diventare il materiale per\n" " eccellenza per l’occhialeria artigianale di alta qualità.\n" " </p>\n" " <p class=\"fe_text4 interlinea1\">\n" " In seguito, sulla scia dei primi successi di “<strong>PERSOL</strong>”, nuova linea di occhiali\n" " destinata nel futuro ad impreziosire la fama dell’industria cittadina, Fabbricatorino iniziò lo\n" " studio e la produzione di <strong>occhiali da sole e da vista</strong> non solo per uso\n" " industriale e sportivo ma anche per la <strong>vita di tutti i giorni</strong>.\n" " </p>\n" " </div>\n" " <div class=\"col-12 col-lg-6 mt-3 d-flex justify-content-center align-items-center order-3 order-lg-4\">\n" " <img src=\"/images/storia2.png\" class=\"img-fluid mr-2 maxWidth\">\n" " <img src=\"/images/storia3.png\" class=\"img-fluid ml-2 maxWidth\">\n" " </div>\n" " <div class=\"col-12 col-lg-6 mt-3 d-flex justify-content-center align-items-center order-5 order-lg-5\">\n" " <img src=\"/images/storia4.png\" class=\"img-fluid mr-2 maxWidth\">\n" " <img src=\"/images/storia5.png\" class=\"img-fluid ml-2 maxWidth\">\n" " </div>\n" " <div class=\"col-12 col-lg-6 mt-3 order-6 order-lg-6\">\n" " <p class=\"fe_text4 interlinea1\">\n" " Da sempre sinonimo di <strong>alta qualità italiana</strong> i nostri occhiali sono fresati dal\n" " pieno da lastre di acetato, <strong>lavorate a mano dai nostri artigiani</strong> e tutti i\n" " passaggi che portano alla nascita del prodotto sono curati con una <strong>attenzione\n" " maniacale</strong>. Fabbricatorino realizza i propri prodotti per tutti coloro che non hanno\n" " bisogno di seguire le mode ma vogliono imporre il proprio <strong>unico modo di essere</strong>.\n" " </p>\n" " <p class=\"fe_text4 interlinea1\">\n" " Le nostre linee seducono una nicchia di consumatori curiosi e attenti, che cercano in un\n" " prodotto la <strong>bellezza</strong> e l’<strong>esclusività</strong> uniti ai valori di\n" " <strong>innovazione, tradizione e sostenibilità</strong>.\n" " </p>\n" " </div>\n" " <div\n" " class=\"col-12 fe_storia_contact justify-content-center align-items-center mt-4 d-none d-lg-flex order-7 order-lg-7\">\n" " <span>Vuoi parlare con noi</span>\n" " <a href=\"mailto:info@fabbricatorino.it\"><i class=\"material-icons\">markunread</i></a>\n" " <a href=\"tel:0110712545\"><i class=\"material-icons\">call</i></a>\n" " </div> \n" " </div>\n" " <div class=\"row d-flex justify-content-center d-lg-none\">\n" " <div class=\"col-8 d-flex justify-content-center\">\n" " <div class=\"fe_storia_category\"\n" " onclick=\"this.style.display=&quot;none&quot;;this.nextElementSibling.classList.remove(&quot;d-none&quot;);this.nextElementSibling.nextElementSibling.classList.remove(&quot;d-none&quot;);\">\n" " <a>\n" " Scopri la collezione <strong style=\"text-transform:uppercase\">VISTA</strong> </a>\n" " </div>\n" " <div class=\"d-none fe_storia_genderW\">\n" " <a href=\"/vista/?gender=F\">\n" " Donna </a>\n" " </div>\n" " <div class=\"d-none fe_storia_genderU\">\n" " <a href=\"/vista/?gender=U\">\n" " Uomo </a>\n" " </div>\n" " </div>\n" " </div>\n" " <div class=\"row d-flex justify-content-center d-lg-none mt-3\">\n" " <div class=\"col-8 d-flex justify-content-center\">\n" " <div class=\"fe_storia_category\"\n" " onclick=\"this.style.display=&quot;none&quot;;this.nextElementSibling.classList.remove(&quot;d-none&quot;);this.nextElementSibling.nextElementSibling.classList.remove(&quot;d-none&quot;);\">\n" " <a>\n" " Scopri la collezione <strong style=\"text-transform:uppercase\">SOLE</strong> </a>\n" " </div>\n" " <div class=\"d-none fe_storia_genderW\">\n" " <a href=\"/sole/?gender=F\">\n" " Donna </a>\n" " </div>\n" " <div class=\"d-none fe_storia_genderU\">\n" " <a href=\"/sole/?gender=U\">\n" " Uomo </a>\n" " </div>\n" " </div>\n" " </div>\n" " </div>\n" " </div>\n\n\n\n" " </section>\n" "@endsection\n") matches = re.finditer(regex, test_str, re.MULTILINE) for matchNum, match in enumerate(matches, start=1): print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group())) for groupNum in range(0, len(match.groups())): groupNum = groupNum + 1 print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum))) # Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.

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 Python, please visit: https://docs.python.org/3/library/re.html