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"(?:Szinnen\s*=\s*)(({{P\d{3}.*}}\s*-\s*)*({{P\d{3}}}))" test_str = "\"{{Infobox chemische stof\\n| Naam = Thionylchloride\\n| afbeelding1 = Thionyl-chloride-2D-dimensions.png\\n| afbeeldingbreedte1 = 120\\n| onderschrift1 = [[Structuurformule]] van thionylchloride\\n| afbeelding2 = Thionyl-chloride-3D-vdW.png\\n| afbeeldingbreedte2 = 120\\n| onderschrift2 = [[Molecuulmodel]] van thionylchloride\\n| afbeelding3 = \\n| onderschrift3 = \\n| afbeelding4 = \\n| onderschrift4 = \\n| IUPAC = \\n| AndereNamen = \\n| Formule= SOCl<sub>2</sub>\\n| SMILES= \\n| EINECS = 231-748-8\\n| EG =\\n| VN = \\n| Beschrijving = Gele vloeistof\\n| CAS = 7719-09-7\\n| AfbWaarsch = {{Pictogram GHS|C|T|X}}\\n| TekstWaarsch = Gevaar<ref name=\\\"MSDS\\\">MSDS Sigma Aldrich, Versie 4.0, Herzieningsdatum 12-3-2010</ref>\\n| Carcinogeen = \\n| Hygroscopisch = reageert met water\\n| Rzinnen = {{H302}} - {{H314+H411+H111}} - {{H318}} - {{H330}} - {{H331}} - {{H332}} - {{H335}}<ref name=\\\"MSDS\\\"/>\\n| EUHzinnen = {{EUH014}} - {{EUH029}}\\n| Szinnen = {{P261}} - {{P264}} - {{P270}} - {{P271}} - {{P280}} - {{P284}} - {{P301+P312}} - {{P301+P330+P331}} - {{P303+P361+P353}} - {{P304+P340}} - {{P305+P351+P338}} - {{P310}} - {{P311}} - {{P312}} - {{P320}} - {{P321}} - {{P330}} - {{P363}} - {{P403+P233}} - {{P405}} - {{P501}}<ref name=\\\"MSDS\\\"/>\\n| Omgang = \\n| Opslag = \\n| ADR = \\n| MAC = \\n| LethaalRat = \\n| LethaalKonijn = \\n| MSDS = \\n| Aggregatie= vloeibaar\\n| Kleur = geel\\n| Dichtheid = 1,638\\n| Molgewicht = 118,97\\n| Smeltpunt = −104,5\\n| Kookpunt = 75,3\\n| Vlampunt = \\n| Zelfontbranding = \\n| Dampdruk = \\n| Oplosbaarheid = \\n| GoedOplIn = \\n| SlechtOplIn = \\n| OnoplIn = \\n| Dipoolmoment = \\n| Viscositeit = 0,06\\n| Kristalstructuur = \\n| fG0g = \\n| fG0l = \\n| fG0s = \\n| fH0g = \\n| fH0l = \\n| fH0s = \\n| S0g = \\n| S0l = \\n| S0s = \\n| Cpm0 = \\n| Evenwicht = \\n| KlassiekeAnalyse = \\n| Spectra = \\n}}\\n\\n'''Thionylchloride''' (of '''thionyldichloride''') is een [[anorganische stof]] met [[chemische formule|formule]] SOCl<sub>2</sub>. SOCl<sub>2</sub> is een reactieve chemische stof die gebruikt wordt in chloreringsreacties. Chemisch gezien is thionylchloride het di[[zuurchloride]] van [[zwaveligzuur]]. Het is een kleurloze tot gele vloeistof bij kamertemperatuur die degradeert boven 140&nbsp;°C. SOCl<sub>2</sub> wordt soms verward met [[sulfurylchloride]], SO<sub>2</sub>Cl<sub>2</sub>, maar de chemische eigenschappen van deze S(IV)- en S(VI)-stoffen zijn zeer verschillend.\\n\\n== Eigenschappen en structuur ==\\nThionylchloride is piramidaal qua structuur, wat aangeeft dat er een [[vrij elektronenpaar]] op het zwavelcentrum zit. Het vergelijkbare molecuul [[fosgeen|COCl<sub>2</sub>]] ([[fosgeen]]) is vlak.\\n\\nThionylchloride reageert met water om zo [[waterstofchloride]] en [[zwaveldioxide]] te vormen.\\n\\n:[[Water|H<sub>2</sub>O]] + O=SCl<sub>2</sub> → SO<sub>2</sub> + 2 HCl\\n\\nVanwege de hoge reactiviteit met water wordt thionylchloride niet aangetroffen in de natuur.\\n\\n==Industrieel gebruik==\\nThionylchloride wordt gebruikt in lithium-thionylchloride-[[batterij (elektrisch)|batterijen]] als het positieve materiaal, met [[Lithium (element)|lithium]] als het negatieve materiaal. Het wordt ook gebruikt als [[reagens]] in de productie van diverse chemische stoffen.\\n\\nThionylchloride wordt gebruikt als grondstof voor [[zenuwgas]]sen uit de G-serie ([[Tabun]], [[Sarin (zenuwgas)|Sarin]] en [[Soman]]).\\n\\n==Gebruik in organische chemie==\\nThionylchloride wordt veel gebruikt om [[carbonzuur|carbonzuren]]<ref>Allen, C. F. H.; Byers, Jr., J. R.; Humphlett, W. J. ''Org. Syn.'', Coll. Vol. 4, p.739 (1963); Vol. 37, p.66 (1957). ([http://www.orgsyn.org/orgsyn/prep.asp?prep=cv4p0739 Artikel])</ref><ref>Rutenberg, M. W.; Horning, E. C. ''Org. Syn.'', Coll. Vol. 4, p.620 (1963); Vol. 30, p.62 (1950). ([http://www.orgsyn.org/orgsyn/prep.asp?prep=cv4p0620 Artikel])</ref> en [[alcohol (scheikunde)|alcoholen]]<ref>Mondanaro, K. R.; Dailey, W. P. ''Org. Syn.'', Coll. Vol. 10, p.212 (2004); Vol. 75, p.89 (1998). ([http://www.orgsyn.org/orgsyn/prep.asp?prep=v75p0089 Artikel])</ref><ref>Krakowiak, K. E.; Bradshaw, J. S. ''Org. Syn.'', Coll. Vol. 9, p.34 (1998); Vol. 70, p.129 (1992). ([http://www.orgsyn.org/orgsyn/prep.asp?prep=cv9p0034 Artikel])</ref> om te zetten in de bijbehorende acylchloriden en alkylchloriden respectievelijk. Het wordt verkozen boven andere reagentia zoals [[fosforpentachloride]] omdat de producten van de thionylchloridereacties, HCl en SO<sub>2</sub>, gassen zijn, wat het zuiveren van het product vereenvoudigt. Een overmaat aan thionylchloride kan verwijderd worden door middel van [[destillatie]].\\n\\n:[[Carbonzuur|RC(O)OH]] + O=SCl<sub>2</sub> → [[Zuurchloride|RC(O)Cl]] + SO<sub>2</sub> + HCl\\n:[[Alcohol (scheikunde)|R-OH]] + O=SCl<sub>2</sub> → [[Halogeenalkaan|R-Cl]] + SO<sub>2</sub> + HCl\\n\\n[[Sulfonzuur|Sulfonzuren]] reageren met thionylchloride om zo [[sulfonylchloride]]s te produceren.<ref>Weinreb, S. M.; Chase, C. E.; Wipf, P.; Venkatraman, S. ''Org. Syn.'', Coll. Vol. 10, p.707 (2004); Vol. 75, p.161 (1998). ([http://www.orgsyn.org/orgsyn/prep.asp?prep=v75p0161 Artikel])</ref><ref>Hazen, G. G.; Bollinger, F. W.; Roberts, F. E.; Russ, W. K.; Seman, J. J.; Staskiewicz, S. ''Org. Syn.'', Coll. Vol. 9, p.400 (1998); Vol. 73, p.144 (1996). ([http://www.orgsyn.org/orgsyn/prep.asp?prep=cv9p0400 Article])</ref>\\n\\n===Diverse reacties===\\nThionylchloride reageert met primaire [[formamide]]s om zo [[isocyanide]]n te vormen.<ref>Niznik, G. E.; Morrison, III, W. H.; Walborsky, H. M. ''Org. Syn.'', Coll. Vol. 6, p.751 (1988); Vol. 51, p.31 (1971). ([http://www.orgsyn.org/orgsyn/prep.asp?prep=cv6p0751 Artikel])</ref>\\n\\n[[Amide]]n reageren met thionylchloride om zo [[imidoylchloriden]] te vormen. Primaire amiden reageren onder verhitting door met thionylchloride om [[nitril]]en te vormen.<ref>Krynitsky, J. A.; Carhart, H. W. ''Org. Syn.'', Coll. Vol. 4, p.436 (1963); Vol. 32, p.65 (1952). ([http://www.orgsyn.org/orgsyn/prep.asp?prep=cv4p0436 Artikel])</ref>\\n\\n== Synthese van thionylchloride ==\\nDe grootschalige industriële synthese is de reactie van [[zwaveltrioxide]] met [[zwaveldichloride]]:<ref>N. N. Greenwood, A. Earnshaw, ''Chemistry of the Elements'', Pergamon Press, 1984.</ref>\\n\\n:[[Zwaveltrioxide|SO<sub>3</sub>]] + [[Zwaveldichloride|SCl<sub>2</sub>]] → '''SOCl<sub>2</sub>''' + SO<sub>2</sub>\\n\\nAndere methoden zijn:\\n\\n:SO<sub>2</sub> + [[Fosforpentachloride|PCl<sub>5</sub>]] → '''SOCl<sub>2</sub>''' + POCl<sub>3</sub>\\n\\n:SO<sub>2</sub> + [[Chloor (element)|Cl<sub>2</sub>]] + SCl<sub>2</sub> → 2 '''SOCl<sub>2</sub>'''\\n\\n:[[Zwaveltrioxide|SO<sub>3</sub>]] + Cl<sub>2</sub> + 2 SCl<sub>2</sub> → 3 '''SOCl<sub>2</sub>'''\\n\\nDe eerste van de drie bovenstaande reacties levert ook [[Fosforylchloride|fosforoxychloride]] op, wat in vele reacties op thionylchloride lijkt.\\n\\n==Veiligheid==\\nSOCl<sub>2</sub> is [[vergif|giftig]] en [[corrosief]]. Het heeft daarnaast een zeer stekende geur.\\n\\n== Zie ook ==\\n* [[Thionylbromide]]\\n\\n{{Appendix}}\\n\\n[[Categorie:Verbinding van zwavel]]\\n[[Categorie:Zuurchloride]]\\n[[Categorie:Corrosieve stof]]\"" 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