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
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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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

/
/
mg

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"(?:P\s*=\s*{{P-Sätze)((\|(\d{3}(\+*))*|\|*\d{3})*)" test_str = "\"{{Infobox Chemikalie\\n| Strukturformel = [[Datei:Sulfurous dichloride 200.svg|130px|Struktur von Thionylchlorid]]\\n| Suchfunktion = Cl2OS\\n| Andere Namen = * Schwefligsäurechlorid\\n* Chlorthionyl\\n* Thionyldichlorid\\n| Summenformel = SOCl<sub>2</sub>\\n| CAS = 7719-09-7\\n| EG-Nummer = 231-748-8\\n| ECHA-ID = 100.028.863\\n| PubChem = 24386\\n| ChemSpider = 22797\\n| Beschreibung = farblose, stark lichtbrechende, erstickend riechende Flüssigkeit<ref name=\\\"roempp\\\">{{RömppOnline|Name=Thionylchlorid|Datum=2. Mai 2014|ID=RD-20-01498}}</ref>\\n| Molare Masse = 118,97 [[Gramm|g]]·[[mol]]<sup>−1</sup>\\n| Aggregat = flüssig\\n| Dichte = 1,638 g·[[Meter|cm]]<sup>−3</sup> (20&nbsp;°C)<ref name=\\\"GESTIS\\\">{{GESTIS|Name=Thionylchlorid|ZVG=1310|CAS=7719-09-7|Datum=8. Januar 2020}}.</ref>\\n| Schmelzpunkt = −104,5 [[Grad Celsius|°C]]<ref name=\\\"GESTIS\\\" />\\n| Siedepunkt = 76 °C<ref name=\\\"GESTIS\\\" />\\n| Dampfdruck = * 124 h[[Pascal (Einheit)|Pa]] (20&nbsp;°C)<ref name=\\\"GESTIS\\\" />\\n* 188 hPa (30 °C)<ref name=\\\"GESTIS\\\" />\\n* 435 hPa (50 °C)<ref name=\\\"GESTIS\\\" />\\n| Löslichkeit = teils heftige Zersetzung mit Wasser und [[Alkohole]]n<ref name=\\\"roempp\\\" />\\n| Brechungsindex = 1,518 (20 °C)<ref name=\\\"Sigma\\\">{{Sigma-Aldrich|sial|88950|Datum=3. Oktober 2016|Name=Thionyl chloride}}</ref>\\n| CLH = {{CLH-ECHA|ID=100.028.863 |Name=Thionyl dichloride |Datum=1. Februar 2016}}\\n| Quelle GHS-Kz = <ref name=\\\"GESTIS\\\" />\\n| GHS-Piktogramme = {{GHS-Piktogramme|06|05}}\\n| GHS-Signalwort = Gefahr\\n| H = {{H-Sätze|111+222|302|331|314|335}}\\n| EUH = {{EUH-Sätze|014+111|029}}\\n| P = {{P-Sätze|280|301+330+331|304+340|305+351+338|308+310}}\\n| Quelle P = <ref name=\\\"GESTIS\\\" />\\n| MAK = Schweiz: 1 ml·m<sup>−3</sup> bzw. 5 mg·m<sup>−3</sup><ref>{{SUVA-MAK |Name=Thionylchlorid |CAS-Nummer=7719-09-7 |Abruf=2015-11-02}}</ref>\\n| ToxDaten = * {{ToxDaten |Typ=LC50 |Organismus=Ratte |Applikationsart=inhalativ |Wert=500–1274 [[Parts per million|ppm]]·1 h |Bezeichnung= |Quelle=<ref name=\\\"GESTIS\\\" /> }}\\n*{{ToxDaten |Typ=LC50 |Organismus=Ratte |Applikationsart=inhalativ |Wert=540 [[Parts per million|ppm]]·4 h |Bezeichnung= |Quelle=<ref name=\\\"GESTIS\\\" /> }}\\n}}\\n\\n'''Thionylchlorid''' ist eine stark lichtbrechende farblose Flüssigkeit, das [[Anorganische Säurehalogenide|Dichlorid]] der [[Schweflige Säure|Schwefligen Säure]].\\n\\n== Geschichte ==\\nThionylchlorid wurde erstmals im Jahre 1849 durch die Umsetzung von [[Schwefeldioxid]] mit [[Phosphorpentachlorid]] erhalten.<ref>M. Persoz: In: ''[[Compt. Rend.]]'' 28, 1849, S. 86–88.</ref><ref>P. Kremers: In: ''[[Justus Liebigs Ann. Chem.]]'' 70, 1848, S. 297–300.</ref> Nachdem seine Eignung als Chlorierungsreagenz erkannt wurde, wurde es etwa ab 1900 im industriellen Maßstab hergestellt und verwendet.<ref name=\\\"Ullmann\\\">H.-D. Lauss, W. Steffens: ''Sulfur Halides.'' In: ''[[Ullmanns Enzyklopädie der Technischen Chemie]].'' Wiley-VCH Verlag, Weinheim 2012, {{DOI|10.1002/14356007.a25_623}}.</ref>\\n\\n== Eigenschaften ==\\n[[Datei:Thionyl-chloride-2D-dimensions.png|mini|links|Bindungslängen und -winkel von Thionylchlorid]]\\nThionylchlorid ist eine farblose bis gelbliche, an der Luft rauchende Flüssigkeit, die sich in Wasser oder bei Erhitzung oder unter Lichteinwirkung zersetzt. Ihre Dämpfe wirken schon bei großer Verdünnung erstickend.<ref name=\\\"GESTIS\\\" /> Die Verbindung reagiert heftig mit Wasser und [[Base (Chemie)|Basen]] sowie mit einigen [[Alkohole]]n. Beim Erhitzen über 80&nbsp;°C zerfällt es in [[Schwefeldioxid]], [[Chlor]] und [[Dischwefeldichlorid]],<ref>''[https://www.uni-muenster.de/Chemie.ac/gefahrstoff/uw-c209.htm Thionylchlorid (7719-09-7)]'', Universität Münster, abgerufen am 4. November 2014.</ref> gemäß der Gleichung:\\n::<math>\\\\mathrm{4 \\\\ SOCl_2 \\\\ \\\\longrightarrow \\\\ 2 \\\\ SO_2 + S_2Cl_2 + 3 \\\\ Cl_2}</math>\\n\\nBei der Reaktion mit Wasser bildet sich [[Chlorwasserstoff]] und Schwefeldioxid:<ref name=\\\"GESTIS\\\" />\\n::<math>\\\\mathrm{SOCl_{2(l)} + H_2O_{(l)} \\\\ \\\\longrightarrow \\\\ 2 \\\\ HCl_{(g)} + SO_{2(g)}}</math>\\n\\n== Herstellung ==\\nThionylchlorid wird im Labor durch Einleiten von [[Schwefeltrioxid]] in [[Schwefeldichlorid]] oder durch Überleiten von [[Schwefeldioxid]] über [[Phosphorpentachlorid]] hergestellt:<ref>G. Brauer (Hrsg.): ''Handbook of Preparative Inorganic Chemistry.'' 2. Auflage. vol. 1, Academic Press, 1963, S. 382–383.</ref>\\n:<math>\\\\mathrm{SCl_2 + SO_3 \\\\ \\\\longrightarrow SOCl_2 + SO_2}</math>\\n:<math>\\\\mathrm{PCl_5 + SO_2 \\\\ \\\\longrightarrow POCl_3 + SOCl_2}</math>\\n\\n== Verwendung ==\\n* In [[Lithium-Thionylchlorid-Batterie]]n als [[Kathode]]nmaterial\\n\\n* Industriell wird Thionylchlorid zur Herstellung folgender Substanzen verwendet:\\n** [[Aromaten|aromatische]] [[Sulfonsäurechlorid]]e\\n** [[Carbonsäurechloride]] aus [[Carbonsäure]]n:<br /><math>\\\\mathrm{R{-}COOH + SOCl_2 \\\\ \\\\longrightarrow \\\\ R{-}CO{-}Cl + SO_2 + HCl}</math>\\n** [[Alkylchlorid]]e aus [[aliphatisch]]en [[Alkohole]]n:<br /><math>\\\\mathrm{R{-}OH + SOCl_2 \\\\ \\\\longrightarrow \\\\ R{-}Cl + SO_2 + HCl}</math>\\n\\n== Einzelnachweise ==\\n<references />\\n\\n[[Kategorie:Schwefelverbindung]]\\n[[Kategorie:Säurechlorid]]\\n[[Kategorie:Sauerstoffverbindung]]\"" 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