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
No Match

r"
"
ms

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"Supersedes:?[\\r\\n ]+[\w\-\s]+[\\r\\n ]+(.*)[\\r\\n ]+Serial Numbers?:?[ \\r\\n]+.*?[ \\n\\r]\*+[\\n\\r ]+\*([A-Za-z ]+)[ \\n\\r]\*+[\\n\\r]+.*?\*+[ \\n\\r]+.*?\*\s+(?:Author[:\w\/]+ ([\.\w\/\s�]+))" test_str = "<html xmlns:msdt=\"uuid:C2F41010-65B3-11d1-A29F-00AA00C14882\" xmlns:mso=\"urn:schemas-microsoft-com:office:office\">\\n <head>\\n <meta charset=\"utf-8\"/>\\n <title>\\n SN G2250-010\\n </title>\\n <!--[if gte mso 9]><xml>\\n<mso:CustomDocumentProperties>\\r\\n<mso:Service_x0020_Note msdt:dt=\"string\">SN</mso:Service_x0020_Note>\\r\\n<mso:Order msdt:dt=\"string\">1493700.00000000</mso:Order>\\r\\n<mso:ContentType msdt:dt=\"string\">Document</mso:ContentType>\\r\\n</mso:CustomDocumentProperties>\\n</xml><![endif]-->\\n </head>\\n <link href=\"..\\\\..\\\\_format.css\" rel=\"stylesheet\" type=\"text/css\"/>\\n <body>\\n <table>\\n <tr>\\n <td>\\n <img border=\"0\" src=\"SN_G2250_010//r1_logo1.gif\"/>\\n </td>\\n <td align=\"left\" width=\"178\">\\n <img border=\"0\" src=\"SN_G2250_010//r1_logo2.gif\"/>\\n </td>\\n <td>\\n <div class=\"subtitle2\">\\n <b>\\n <font color=\"red\">\\n Life Sciences and Chemical Analysis Service Note\\n </font>\\n </b>\\n </div>\\n </td>\\n </tr>\\n </table>\\n <h2>\\n SERVICE NOTE G2250-010\\n </h2>\\n <pre>Supersedes: None\\r\\n \\r\\nINB22000 compatibility with Windows 2000 and ChemStation A.9.01\\r\\n\\r\\nSerial Numbers:\\r\\nUS00000000 - US99999999\\r\\n\\r\\nThe CCMode software is in general compatible with Windows 2000 and \\r\\nChemStation Revision A.9.01. Please see required settings!\\r\\n\\r\\nTo Be Performed By:\\r\\nAgilent-Qualified Personnel\\r\\n\\r\\nParts Required:\\r\\n\\r\\nNone\\r\\n\\r\\nSituation:\\r\\nChanges of operating software to Windows 2000 and implementation\\r\\nof ChemStation Rev. A.9.01 required some testing of the CCMode \\r\\n\\r\\nsoftware INB22000 / INB22002 / INB22003 and INB22004 Rev. A.03.02.\\r\\n\\r\\nSolution/Action:\\r\\nBefore using the Micro-plate Sampling Software INB22000 / INB22002 \\r\\n/ INB22003 or INB22004 Rev. A.03.02 (CCMode) on a PC with \\r\\nWindows 2000 a minor change in the \"Control panel\" must be made. \\r\\nIf this change is not made some icons in the user interface will \\r\\nnot be represented correctly. The functionality itself is not \\r\\ninfluenced:\\r\\n\\r\\nOpen \"Settings\", \"Control Panel\", \"Display\", \"Appearance\".\\r\\n\\r\\nGo to the \"Scheme\" and select the choice \"Windows Classic\". \\r\\nPress \"OK\" and close the \"Control Panel\" window.Required \"Regional \\r\\nSettings\" for both WIN NT and WIN2000\\r\\n\\r\\nIn order to run and edit parameters within CC-Mode your \\r\\nPC must be setup in this way:\\r\\n\\r\\n- Regional settings: English (United States)\\r\\n- Number format (default for English (United States)) \\r\\n Decimal symbol \\'.\\'\\r\\n- Number format (default for English (United States)) \\r\\n Digit grouping symbol \\',\\'\\r\\n\\r\\nNotes about using WIN2000:\\r\\n\\r\\n1. The installation and operation of CCMode (A.03.0x) and \\r\\nPurify SW (A.01.01) on the same PC is not recommended and \\r\\nnot supported.\\r\\n\\r\\n2. CCMode A.03.01 has not been tested. Customers owning \\r\\nthis version must upgrade to A.03.02 even if the additional \\r\\nfeatures for preparative analysis are not needed.\\r\\n\\r\\n3. The combination CCmode A.03.0x, ChemStation A.08.0x and \\r\\nWindows 2000 has not been tested and is not supported.\\r\\n\\r\\n\\r\\n\\r\\nDate:\\r\\n3/11/02\\r\\n******************************************************************************\\r\\n\\r\\n* Information Only *\\r\\n******************************************************************************\\r\\n* Author/Entity: AG/B404 *\\r\\n* Additional Information: None *\\r\\n******************************************************************************\\r\\n</pre>\\n </body>\\n</html>\\n" matches = re.search(regex, test_str, re.MULTILINE | re.DOTALL) if matches: print ("Match was found at {start}-{end}: {match}".format(start = matches.start(), end = matches.end(), match = matches.group())) for groupNum in range(0, len(matches.groups())): groupNum = groupNum + 1 print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = matches.start(groupNum), end = matches.end(groupNum), group = matches.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