Regular Expressions 101

Save & Share

  • Regex Version: ver. 5
  • 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

/
/
g

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"<a\s*[^>]*?>(?![^<]*?All).*?<\/a>" test_str = ("<!DOCTYPE html>\n" "<html dir=\"ltr\" lang=\"en\" xml:lang=\"en\">\n\n\n\n\n\n\n\n\n\n\n\n\n\n" "<div id=\"page\" class=\"container-fluid clearfix\">\n" " <div id=\"page-content\" class=\"row-fluid\">\n" " <div id=\"region-bs-main-and-pre\" class=\"span9\">\n" " <div class=\"row-fluid\">\n" " <section id=\"region-main\" class=\"span8 pull-right\">\n" " <div role=\"main\"><span id=\"maincontent\"></span><div class=\"no-overflow\"><table cellspacing=\"0\" id=\"overview-grade\" class=\"flexible boxaligncenter generaltable\"><thead><tr><th class=\"header c0\" scope=\"col\">Course name<div class=\"commands\"></div></th><th class=\"header c1\" scope=\"col\">Grade<div class=\"commands\"></div></th></tr></thead><tbody><tr class=\"\" id=\"grade-report-overview-45567_r0\"><td class=\"cell c0\" id=\"grade-report-overview-45567_r0_c0\"><a href=\"https://odtuclass.metu.edu.tr/course/user.php?mode=grade&amp;id=723&amp;user=45567\">[BIOL 107 Section 1] Concepts in Biology</a></td><td class=\"cell c1\" id=\"grade-report-overview-45567_r0_c1\">-</td></tr><tr class=\"\" id=\"grade-report-overview-45567_r1\"><td class=\"cell c0\" id=\"grade-report-overview-45567_r1_c0\"><a href=\"https://odtuclass.metu.edu.tr/course/user.php?mode=grade&amp;id=5153&amp;user=45567\">[CENG 230 All Sections] Introduction to C Programming</a></td><td class=\"cell c1\" id=\"grade-report-overview-45567_r1_c1\">-</td></tr><tr class=\"\" id=\"grade-report-overview-45567_r2\"><td class=\"cell c0\" id=\"grade-report-overview-45567_r2_c0\"><a href=\"https://odtuclass.metu.edu.tr/course/user.php?mode=grade&amp;id=3054&amp;user=45567\">[CENG 230 Section 7] Introduction to C Programming</a></td><td class=\"cell c1\" id=\"grade-report-overview-45567_r2_c1\">-</td></tr><tr class=\"\" id=\"grade-report-overview-45567_r3\"><td class=\"cell c0\" id=\"grade-report-overview-45567_r3_c0\"><a href=\"https://odtuclass.metu.edu.tr/course/user.php?mode=grade&amp;id=3538&amp;user=45567\">[ENG 101 Section 40] English for Academic Purposes I</a></td><td class=\"cell c1\" id=\"grade-report-overview-45567_r3_c1\">37.25</td></tr><tr class=\"\" id=\"grade-report-overview-45567_r4\"><td class=\"cell c0\" id=\"grade-report-overview-45567_r4_c0\"><a href=\"https://odtuclass.metu.edu.tr/course/user.php?mode=grade&amp;id=3208&amp;user=45567\">[FDE 101 Section 1] Introduction to Food Engineering</a></td><td class=\"cell c1\" id=\"grade-report-overview-45567_r4_c1\">55.33</td></tr><tr class=\"\" id=\"grade-report-overview-45567_r5\"><td class=\"cell c0\" id=\"grade-report-overview-45567_r5_c0\"><a href=\"https://odtuclass.metu.edu.tr/course/user.php?mode=grade&amp;id=5358&amp;user=45567\">[MATH 119 All Sections] Calculus with Analytic Geometry</a></td><td class=\"cell c1\" id=\"grade-report-overview-45567_r5_c1\">-</td></tr><tr class=\"\" id=\"grade-report-overview-45567_r6\"><td class=\"cell c0\" id=\"grade-report-overview-45567_r6_c0\"><a href=\"https://odtuclass.metu.edu.tr/course/user.php?mode=grade&amp;id=578&amp;user=45567\">[MATH 119 Section 15] Calculus with Analytic Geometry</a></td><td class=\"cell c1\" id=\"grade-report-overview-45567_r6_c1\">-</td></tr><tr class=\"\" id=\"grade-report-overview-45567_r7\"><td class=\"cell c0\" id=\"grade-report-overview-45567_r7_c0\"><a href=\"https://odtuclass.metu.edu.tr/course/user.php?mode=grade&amp;id=219&amp;user=45567\">[PHYS 105 Section 16] General Physics I</a></td><td class=\"cell c1\" id=\"grade-report-overview-45567_r7_c1\">-</td></tr><h3>Courses I am taking</h3><br /><tr class=\"emptyrow\" id=\"grade-report-overview-45567_r8\"><td class=\"cell c0\" id=\"grade-report-overview-45567_r8_c0\"></td><td class=\"cell c1\" id=\"grade-report-overview-45567_r8_c1\"></td></tr><tr class=\"emptyrow\" id=\"grade-report-overview-45567_r9\"><td class=\"cell c0\" id=\"grade-report-overview-45567_r9_c0\"></td><td class=\"cell c1\" id=\"grade-report-overview-45567_r9_c1\"></td></tr><tr class=\"emptyrow\" id=\"grade-report-overview-45567_r10\"><td class=\"cell c0\" id=\"grade-report-overview-45567_r10_c0\"></td><td class=\"cell c1\" id=\"grade-report-overview-45567_r10_c1\"></td></tr><tr class=\"emptyrow\" id=\"grade-report-overview-45567_r11\"><td class=\"cell c0\" id=\"grade-report-overview-45567_r11_c0\"></td><td class=\"cell c1\" id=\"grade-report-overview-45567_r11_c1\"></td></tr><tr class=\"emptyrow\" id=\"grade-report-overview-45567_r12\"><td class=\"cell c0\" id=\"grade-report-overview-45567_r12_c0\"></td><td class=\"cell c1\" id=\"grade-report-overview-45567_r12_c1\"></td></tr><tr class=\"emptyrow\" id=\"grade-report-overview-45567_r13\"><td class=\"cell c0\" id=\"grade-report-overview-45567_r13_c0\"></td><td class=\"cell c1\" id=\"grade-report-overview-45567_r13_c1\"></td></tr><tr class=\"emptyrow\" id=\"grade-report-overview-45567_r14\"><td class=\"cell c0\" id=\"grade-report-overview-45567_r14_c0\"></td><td class=\"cell c1\" id=\"grade-report-overview-45567_r14_c1\"></td></tr><tr class=\"emptyrow\" id=\"grade-report-overview-45567_r15\"><td class=\"cell c0\" id=\"grade-report-overview-45567_r15_c0\"></td><td class=\"cell c1\" id=\"grade-report-overview-45567_r15_c1\"></td></tr><tr class=\"emptyrow\" id=\"grade-report-overview-45567_r16\"><td class=\"cell c0\" id=\"grade-report-overview-45567_r16_c0\"></td><td class=\"cell c1\" id=\"grade-report-overview-45567_r16_c1\"></td></tr><tr class=\"emptyrow\" id=\"grade-report-overview-45567_r17\"><td class=\"cell c0\" id=\"grade-report-overview-45567_r17_c0\"></td><td class=\"cell c1\" id=\"grade-report-overview-45567_r17_c1\"></td></tr><tr class=\"emptyrow\" id=\"grade-report-overview-45567_r18\"><td class=\"cell c0\" id=\"grade-report-overview-45567_r18_c0\"></td><td class=\"cell c1\" id=\"grade-report-overview-45567_r18_c1\"></td></tr><tr class=\"emptyrow\" id=\"grade-report-overview-45567_r19\"><td class=\"cell c0\" id=\"grade-report-overview-45567_r19_c0\"></td><td class=\"cell c1\" id=\"grade-report-overview-45567_r19_c1\"></td></tr><tr class=\"emptyrow\" id=\"grade-report-overview-45567_r20\"><td class=\"cell c0\" id=\"grade-report-overview-45567_r20_c0\"></td><td class=\"cell c1\" id=\"grade-report-overview-45567_r20_c1\"></td></tr><tr class=\"emptyrow\" id=\"grade-report-overview-45567_r21\"><td class=\"cell c0\" id=\"grade-report-overview-45567_r21_c0\"></td><td class=\"cell c1\" id=\"grade-report-overview-45567_r21_c1\"></td></tr><tr class=\"emptyrow\" id=\"grade-report-overview-45567_r22\"><td class=\"cell c0\" id=\"grade-report-overview-45567_r22_c0\"></td><td class=\"cell c1\" id=\"grade-report-overview-45567_r22_c1\"></td></tr><tr class=\"emptyrow\" id=\"grade-report-overview-45567_r23\"><td class=\"cell c0\" id=\"grade-report-overview-45567_r23_c0\"></td><td class=\"cell c1\" id=\"grade-report-overview-45567_r23_c1\"></td></tr><tr class=\"emptyrow\" id=\"grade-report-overview-45567_r24\"><td class=\"cell c0\" id=\"grade-report-overview-45567_r24_c0\"></td><td class=\"cell c1\" id=\"grade-report-overview-45567_r24_c1\"></td></tr><tr class=\"emptyrow\" id=\"grade-report-overview-45567_r25\"><td class=\"cell c0\" id=\"grade-report-overview-45567_r25_c0\"></td><td class=\"cell c1\" id=\"grade-report-overview-45567_r25_c1\"></td></tr><tr class=\"emptyrow\" id=\"grade-report-overview-45567_r26\"><td class=\"cell c0\" id=\"grade-report-overview-45567_r26_c0\"></td><td class=\"cell c1\" id=\"grade-report-overview-45567_r26_c1\"></td></tr><tr class=\"emptyrow\" id=\"grade-report-overview-45567_r27\"><td class=\"cell c0\" id=\"grade-report-overview-45567_r27_c0\"></td><td class=\"cell c1\" id=\"grade-report-overview-45567_r27_c1\"></td></tr><tr class=\"emptyrow\" id=\"grade-report-overview-45567_r28\"><td class=\"cell c0\" id=\"grade-report-overview-45567_r28_c0\"></td><td class=\"cell c1\" id=\"grade-report-overview-45567_r28_c1\"></td></tr><tr class=\"emptyrow\" id=\"grade-report-overview-45567_r29\"><td class=\"cell c0\" id=\"grade-report-overview-45567_r29_c0\"></td><td class=\"cell c1\" id=\"grade-report-overview-45567_r29_c1\"></td></tr></tbody></table></div></div> </section>\n" " </div>\n" " </div>\n" " </div>\n" "</div>\n" " \n\n" " \n\n\n\n\n\n\n\n\n" "</body>\n" "</html>\n" " ") matches = re.finditer(regex, test_str) 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