Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • Update Regex
  • Save new Regex
  • Add to Community Library


  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8
  • .NET 7.0 (C#)
  • Rust
  • Regex Flavor Guide


  • Match
  • Substitution
  • List
  • Unit Tests


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
  • A character except: a, b or c
  • A character in the range: a-z
  • A character not in the range: a-z
  • A character in the range: a-z or A-Z
  • Any single character
  • Alternate - match either a or b
  • Any whitespace character
  • Any non-whitespace character
  • Any digit
  • Any non-digit
  • Any word character
  • Any non-word character
  • Match everything enclosed
  • Capture everything enclosed
  • Zero or one of a
  • Zero or more of a
  • One or more of a
  • Exactly 3 of a
  • 3 or more of a
  • Between 3 and 6 of a
  • Start of string
  • End of string
  • A word boundary
  • Non-word boundary

Regular Expression


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"iPhone [6-7]" test_str = ("iPhone 7 Plus\n" "iPad Pro 12.9 2015 iOS15.5 beta 4\n" "iPhone 11 Pro iOS15.5 beta4\n" "iPad Pro 10.5 2017\n" "iPad 9.7 2018 iOS15.5 beta4\n" "iPhone X \n" "iPhone 11 Pro Max\n" "iPad Pro 10.5 2017\n" "iPad mini 3\n" "iPhone X\n" "iPad Pro 12.9 2021\n" "iPhone 13\n" "iPhone 11\n" "iPhone 12 mini\n" "iPad Pro 12.9 2018\n" "iPad Pro 11 2018\n" "iPhone 12\n" "iPhone X iOS15.5 beta4\n" "iPad Air 2\n" "iPhone 8\n" "iPhone 6\n" "iPhone XS Max\n" "iPad mini 4\n" "iPad Air 3 (2019)\n" "iPhone SE 2020\n" "iPhone 11 Pro\n" "iPhone 12 Pro\n" "iPad Mini 2019\n" "iPad 9.7 2018\n" "iPad 10.2 2020\n" "iPhone SE\n" "iPad Air 2\n" "iPad Air 2022 5th Gen\n" "iPad Air 2020\n" "iPad Air 2\n" "iPad Pro 11 2021\n" "iPhone SE 2020\n" "iPhone 6 Plus\n" "iPad Pro 11 2020\n" "iPad 10.2 2020\n" "iPad Pro 10.5 2017\n" "iPad 10.2\n" "iPhone XR\n" "iPad Pro 12.9 2015\n" "iPad Pro\n" "iPad Air 2\n" "iPhone 7\n" "iPad Mini 2021 6th Gen\n" "iPad Air 2020\n" "iPhone 8 Plus\n" "iPhone 11\n" "iPad 9.7 2017 5th Gen\n" "iPhone XS\n" "iPad Pro 12.9 2020\n" "iPhone 6S\n" "iPad Air\n" "iPhone XS Max\n" "iPhone SE 2020\n" "iPhone_11_Pro\n" "iPhone 5S\n" "iPhone 8\n" "iPhone 7 Plus\n" "iPod Touch 6\n" "iPad Pro 9.7\n" "iPhone 12 mini iOS15.5 beta4\n" "iPhone X\n" "iPhone 8\n" "iPhone 6\n" "iPhone X\n" "iPhone 13 Pro Max\n" "iPhone 12 Pro Max\n" "iPad Air 2 iOS15.5 beta4\n" "iPhone 6\n" "iPad mini 4\n" "iPad Pro 11 2018\n" "iPad Pro 12.9 2015\n" "iPhone XR\n" "iPhone XS\n" "iPhone XR\n" "iPhone 7\n" "iPad Pro 12.9 2017\n" "iPhone 8\n" "iPhone 6S\n" "iPad Pro 12.9 2017\n" "iPad Pro 12.9\n" "iPhone X \n" "iPhone 8 Plus\n" "iPad Air 3 (2019)\n" "iPhone 8\n" "iPhone 12 Pro Max\n" "iPad Pro 12.9 2015\n" "iPad mini 4\n" "iPhone 13 mini\n" "iPad Air 2\n" "iPhone 13 Pro\n" "iPhone 7\n" "iPhone XS\n" "iPad 10.2 2021 9th Gen\n" "iPhone SE 2020\n" "iPod Touch 7\n" "iPad Air 2\n" "iPhone 7 Plus\n" "iPhone SE 2022\n" "iPhone 6S Plus\n" "iPhone 12") 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 = 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 = # 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: