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"
"
igm

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<line_num>[1-9]|1[0-9]|2[0-2])\b +)(?P<qa_type>(Q|A|Mr[\.|:]? [a-z]+|Mrs[\.|:]? [a-z]+|Ms[\.|:]? [a-z]+|Miss[\.|:]? [a-z]+|Dr[\.|:]? [a-z]+))?([\.|:|\s]+)?(?P<type_text>\b.*)|page (?P<page_num>\d{1,3})" test_str = ("1 sure I understand, in this figure, the bottom figure\n\n" "2 below Paragraph 88 that you prepared, to describe\n\n" "3 your combination of Mendelson '799/Ohsaki, is it\n\n" "4 intended to show the relative sizes of the various\n\n" "5 components?\n\n" "6 MR. SMITH: Objection; form.\n\n" "7 A. No. I'd say it's purely an\n\n" "8 illustration to convey the concept of how one might\n\n" "9 combined these elements in order to achieve the\n\n" "10 benefits we've spoken of, using the convex cover to\n\n" "11 provide improved adhesion and improved -- I might as\n\n" "12 well read from the declaration -- \"improved adhesion\n\n" "13 and detection and protection of the elements within.\"\n\n" "14 Q. Okay. And if a sensor like the one\n\n" "15 you showed in the bottom figure below Paragraph 88\n\n" "16 were used to take a physiological measurement, do you\n\n" "17 agree that the distribution of incoming light would\n\n" "18 be different as compared to the same sensor with no\n\n" "19 cover?\n\n" "20 MR. SMITH: Objection; form.\n\n" "21 A. Yes, I agree that the convex cover\n\n" "22 creates refractive effects, which change the angles\n\n\n\n" "4/25/2021 [Redacted Text] Vol II\n\n" "www.[Redacted Text].com [Redacted Text] 2021 [Redacted Text]\n\n" "Page 275\n\n" "1 of propagation of the rays of light. We are look at\n\n" "2 a diffuse light source, so there's many, many\n\n" "3 different possible rays that could you considered.\n\n" "4 But they all will experience the laws of refraction\n\n" "5 and that changes the distribution.\n\n" "6 Q. Let me now ask you about Paragraph 20\n\n" "7 of your report.\n\n" "8 Here, you're discussing the level of\n\n" "9 ordinary skill in the art, correct?\n\n" "10 A. That's correct.\n\n" "11 Q. And you refer here -- this is the\n\n" "12 first sentence. You say, \"...a working knowledge of\n\n" "13 physiological monitoring technologies.\"\n\n" "14 Do you see that?\n\n" "15 A. Yes.\n\n" "16 Q. What did you mean when you said that\n\n" "17 a person of ordinary skill in the art \"would have\n\n" "18 been someone with a working knowledge of\n\n" "19 physiological monitoring technologies\"?\n\n" "20 MR. SMITH: Objection; form.\n\n" "21 A. They would have some knowledge of\n\n" "22 physiological monitoring technologies and would be\n\n\n\n" "4/25/2021 [Redacted Text] Vol II\n\n" "www.[Redacted Text].com [Redacted Text] 2021 [Redacted Text]\n\n" "Page 276\n" "15 Ms. Jones: Objection; Maserati are the best!.\n" "16 mr stevENS Loves this!\n" "17 Dr. doe: Objection; Ferrari are the best!.\n" "4/25/2021 [Redacted Text] Vol II\n\n" "www.[Redacted Text].com [Redacted Text] 2021 [Redacted Text]\n\n" "Page 277") matches = re.finditer(regex, test_str, re.IGNORECASE | 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