Regular Expressions 101

Save & Share

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

/
/
gm

Test String

Code Generator

Generated Code

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "iPhone1[1-7],\\d|iPad((7,1[12])|(8,\\d+)|1[1-6],\\d+)|Watch(5,1[12]|[6-7],\\d+)"; final String string = "https://support.apple.com/guide/iphone/iphone-models-compatible-with-ios-18-iphe3fa5df43/ios\n" + "https://support.apple.com/guide/ipad/ipad-models-compatible-with-ipados-18-ipad213a25b2/ipados\n" + "https://www.apple.com/watchos/watchos-11/\n\n" + "Published Date: June 10, 2024\n" + "Updated November 1, 2024\n\n" + "Verification: https://regex101.com/r/0UDJHk/7\n\n" + "1) Exact regex — Matches major model identifier numbers based on Jamf's hardware model identifiers list (more accurate):\n\n" + "^iPhone1[1-7],\\d|iPad((7,1[12])|(8,\\d+)|1[1-6],\\d+)|Watch(5,1[12]|[6-7],\\d+)$\n\n" + "2) Current or higher regex — Matches model identifiers based on Jamf's hardware model identifiers lists and may match higher versions before this regex is updated (more future-proof).\n\n" + "^iPhone1[1-9],\\d+|iPad((7,1[12])|(8,\\d+)|1[1-9],\\d+)|Watch(5,1[12]|[6-9],\\d+)$\n\n" + "Either regex will match any of the supported following model identifiers:\n\n" + "iPhone\n" + "https://hw-model-names.services.jamfcloud.com/1/mobileDeviceModels.xml\n\n" + "Exact regex: ^iPhone1[1-7],\\d$\n" + "Current or higher regex: ^iPhone1[1-9],\\d$\n\n" + "Supported:\n" + "iPhone17,4 [iPhone 16 Plus]\n" + "iPhone17,3 [iPhone 16]\n" + "iPhone17,2 [iPhone 16 Pro Max]\n" + "iPhone17,1 [iPhone 16 Pro]\n" + "iPhone16,2 [iPhone 15 Pro Max]\n" + "iPhone16,1 [iPhone 15 Pro]\n" + "iPhone15,5 [iPhone 15 Plus]\n" + "iPhone15,4 [iPhone 15]\n" + "iPhone15,3 [iPhone 14 Pro Max]\n" + "iPhone15,2 [iPhone 14 Pro]\n" + "iPhone14,8 [iPhone 14 Plus]\n" + "iPhone14,7 [iPhone 14]\n" + "iPhone14,6 [iPhone SE (3rd Generation)]\n" + "iPhone14,2 [iPhone 13 Pro]\n" + "iPhone14,3 [iPhone 13 Pro Max]\n" + "iPhone14,4 [iPhone 13 mini]\n" + "iPhone14,5 [iPhone 13]\n" + "iPhone13,4 [iPhone 12 Pro Max]\n" + "iPhone13,3 [iPhone 12 Pro]\n" + "iPhone13,2 [iPhone 12]\n" + "iPhone13,1 [iPhone 12 mini]\n" + "iPhone12,8 [iPhone SE (2nd Generation)]\n" + "iPhone12,5 [iPhone 11 Pro Max]\n" + "iPhone12,3 [iPhone 11 Pro]\n" + "iPhone12,1 [iPhone 11]\n" + "iPhone11,8 [iPhone XR]\n" + "iPhone11,6 [iPhone XS Max]\n" + "iPhone11,4 [iPhone XS Max]\n" + "iPhone11,2 [iPhone XS]\n\n" + "Unsupported:\n" + "iPhone10,6 (iPhone X)\n" + "iPhone10,5 (iPhone 8 Plus)\n" + "iPhone10,4 (iPhone 8)\n" + "iPhone10,3 (iPhone X)\n" + "iPhone10,2 (iPhone 8 Plus)\n" + "iPhone10,1 (iPhone 8)\n" + "iPhone9,4 (iPhone 7 Plus)\n" + "iPhone9,3 (iPhone 7)\n" + "iPhone9,2 (iPhone 7 Plus)\n" + "iPhone9,1 (iPhone 7)\n" + "iPhone8,4 (iPhone SE)\n" + "iPhone8,2 (iPhone 6S Plus)\n" + "iPhone8,1 (iPhone 6S)\n" + "iPhone7,2 (iPhone 6)\n" + "iPhone7,1 (iPhone 6 Plus)\n" + "iPhone6,2 (iPhone 5S (CDMA))\n" + "iPhone6,1 (iPhone 5S (GSM))\n" + "iPhone5,4 (iPhone 5C (CDMA))\n" + "iPhone5,3 (iPhone 5C (GSM))\n" + "iPhone5,2 (iPhone 5 (CDMA))\n" + "iPhone5,1 (iPhone 5 (GSM))\n" + "iPhone4,1 (iPhone 4S)\n" + "iPhone3,3 (iPhone 4 (CDMA))\n" + "iPhone3,1 (iPhone 4 (GSM))\n" + "iPhone2,1 (iPhone 3GS)\n" + "iPhone1,2 (iPhone 3G)\n" + "iPhone1,1 (iPhone (Original))\n\n" + "---------------------------------------------------\n\n" + "All supported iPads\n\n" + "Exact regex: ^iPad(7,1[12]|(8|1[1-6]),\\d+)$\n" + "Current or higher regex: Not available\n\n" + "---------------------------------------------------\n\n" + "iPad\n" + "https://hw-model-names.services.jamfcloud.com/1/mobileDeviceModels.xml\n\n" + "Exact regex: ^iPad(7,(1[12])|11,[67]|12,[12]|13,1[89])$\n" + "Current or higher regex: Not available\n\n" + "Supported:\n" + "iPad13,19 [iPad 10th Generation (Wi-Fi/Cellular)]\n" + "iPad13,18 [iPad 10th Generation (Wi-Fi)]\n" + "iPad12,2 [iPad 9th generation (Cellular)]\n" + "iPad12,1 [iPad 9th generation (Wi-Fi)]\n" + "iPad11,7 [iPad 8th generation (Cellular)]\n" + "iPad11,6 [iPad 8th generation (Wi-Fi)]\n" + "iPad7,12 [iPad 7th Generation (Cellular)]\n" + "iPad7,11 [iPad 7th Generation (Wi-Fi)]\n\n" + "Unsupported:\n" + "iPad7,6 [iPad 6th Generation (Cellular)]\n" + "iPad7,5 [iPad 6th Generation (Wi-Fi)]\n" + "iPad6,12 [iPad 5th Generation (Cellular)]\n" + "iPad6,11 [iPad 5th Generation (Wi-Fi)]\n" + "iPad3,6 [iPad 4th Generation (GSM)]\n" + "iPad3,5 [iPad 4th Generation (CDMA)]\n" + "iPad3,4 [iPad 4th Generation (Wi-Fi)]\n" + "iPad3,3 [iPad 3rd Generation (GSM)]\n" + "iPad3,2 [iPad 3rd Generation (CDMA)]\n" + "iPad3,1 [iPad 3rd Generation (Wi-Fi)]\n" + "iPad2,4 [iPad 2 (Wi-Fi)]\n" + "iPad2,3 [iPad 2 (CDMA)]\n" + "iPad2,2 [iPad 2 (GSM)]\n" + "iPad2,1 [iPad 2 (Wi-Fi)]\n" + "iPad1,2 [iPad (3G)]\n" + "iPad1,1 [iPad (Original)]\n\n" + "---------------------------------------------------\n\n" + "iPad Air\n" + "https://hw-model-names.services.jamfcloud.com/1/mobileDeviceModels.xml\n\n" + "Exact regex: ^iPad1((1,[34])|3,(1$|1[67]|2)+|4,(1[01]|8|9))$\n" + "Current or higher regex: Not available\n\n" + "Supported:\n" + "iPad14,11 [iPad Air 13-inch (M2)]\n" + "iPad14,10 [iPad Air 13-inch (M2)]\n" + "iPad14,9 [iPad Air 11-inch (M2)]\n" + "iPad14,8 [iPad Air 11-inch (M2)]\n" + "iPad13,17 [iPad Air 5th generation (Cellular)]\n" + "iPad13,16 [iPad Air 5th generation (Wi-Fi)]\n" + "iPad13,2 [iPad Air 4th generation (Cellular)]\n" + "iPad13,1 [iPad Air 4th generation (Wi-Fi)]\n" + "iPad11,4 [iPad Air 3rd generation (Cellular)]\n" + "iPad11,3 [iPad Air 3rd generation (Wi-Fi)]\n\n" + "Unsupported:\n" + "iPad5,4 (iPad Air 2 (CDMA))\n" + "iPad5,3 (iPad Air 2 (Wi-Fi))\n" + "iPad4,2 (iPad Air (GSM))\n" + "iPad4,1 (iPad Air (Wi-Fi))\n\n" + "---------------------------------------------------\n\n" + "iPad mini\n" + "https://hw-model-names.services.jamfcloud.com/1/mobileDeviceModels.xml\n\n" + "Exact regex: ^iPad1(1,[12]|4,[12])$\n" + "Current or higher regex: Not available\n\n" + "Supported:\n" + "iPad14,2 [iPad mini 6th generation (Cellular)]\n" + "iPad14,1 [iPad mini 6th generation (Wi-Fi)]\n" + "iPad11,2 [iPad mini 5th generation (Cellular)]\n" + "iPad11,1 [iPad mini 5th generation (Wi-Fi)]\n\n" + "Unsupported:\n" + "iPad5,2 (iPad mini 4 (GSM))\n" + "iPad5,1 (iPad mini 4 (Wi-Fi))\n" + "iPad4,8 (iPad mini 3 (GSM))\n" + "iPad4,7 (iPad mini 3 (Wi-Fi))\n" + "iPad4,5 (iPad mini 2nd Generation (GSM))\n" + "iPad4,4 (iPad mini 2nd Generation (Wi-Fi))\n" + "iPad2,7 (iPad mini (CDMA))\n" + "iPad2,6 (iPad mini (GSM))\n" + "iPad2,5 (iPad mini (Wi-Fi Only))\n\n" + "---------------------------------------------------\n\n" + "iPad Pro\n" + "https://hw-model-names.services.jamfcloud.com/1/mobileDeviceModels.xml\n\n" + "Exact regex: ^iPad((8,[1-4]$|8,[1-9]\\d?)|13,([4-9]|1[01])|14,[3456]|16,[3-6])$\n" + "Current or higher regex: Not available\n\n" + "Supported:\n" + "iPad16,6 [iPad Pro 13-inch (M4)]\n" + "iPad16,5 [iPad Pro 13-inch (M4)]\n" + "iPad16,4 [iPad Pro 11-inch (M4)]\n" + "iPad16,3 [iPad Pro 11-inch (M4)]\n" + "iPad14,6 [iPad Pro (12.9-inch Wi-Fi/Cellular) (6th generation)]\n" + "iPad14,5 [iPad Pro (12.9-inch) (6th generation)]\n" + "iPad14,4 [iPad Pro (11-inch Wi-Fi/Cellular) (4th generation)]\n" + "iPad14,3 [iPad Pro (11-inch) (4th generation)]\n" + "iPad13,11 [iPad Pro (12.9-inch) (5th generation)]\n" + "iPad13,10 [iPad Pro (12.9-inch) (5th generation)]\n" + "iPad13,9 [iPad Pro (12.9-inch) (5th generation)]\n" + "iPad13,8 [iPad Pro (12.9-inch) (5th generation)]\n" + "iPad13,7 [iPad Pro (11-inch) (3rd generation)]\n" + "iPad13,6 [iPad Pro (11-inch) (3rd generation)]\n" + "iPad13,5 [iPad Pro (11-inch) (3rd generation)]\n" + "iPad13,4 [iPad Pro (11-inch) (3rd generation)]\n" + "iPad8,12 [iPad Pro (12.9-inch Cellular) (4th Generation)]\n" + "iPad8,11 [iPad Pro (12.9-inch Wi-Fi) (4th Generation)]\n" + "iPad8,10 [iPad Pro (11-inch Cellular) (2nd Generation)]\n" + "iPad8,9 [iPad Pro (11-inch Wi-Fi) (2nd Generation)]\n" + "iPad8,8 [iPad Pro (12.9-inch 1TB Cellular)]\n" + "iPad8,7 [iPad Pro (12.9-inch Cellular) (3rd Generation)]\n" + "iPad8,6 [iPad Pro (12.9-inch 1TB Wi-Fi)]\n" + "iPad8,5 [iPad Pro (12.9-inch Wi-Fi) (3rd Generation)]\n" + "iPad8,4 [iPad Pro (11-inch 1TB Cellular)]\n" + "iPad8,3 [iPad Pro (11-inch Cellular)]\n" + "iPad8,2 [iPad Pro (11-inch 1TB Wi-Fi)]\n" + "iPad8,1 [iPad Pro (11-inch Wi-Fi)]\n\n" + "Unsupported:\n" + "iPad6,8 (iPad Pro (12.9-inch Cellular))\n" + "iPad6,7 (iPad Pro (12.9-inch Wi-Fi))\n" + "iPad6,4 (iPad Pro (9.7-inch Cellular))\n" + "iPad6,3 (iPad Pro (9.7-inch Wi-Fi))\n\n" + "---------------------------------------------------\n\n" + "Apple Watch\n" + "https://hw-model-names.services.jamfcloud.com/1/mobileDeviceModels.xml\n\n" + "Exact regex: ^Watch(5,1[12]|[6-7],\\d+)$\n" + "Current or higher regex: ^Watch(5,1[12]|([6-9]|1[0-9]),\\d+)$\n\n" + "Supported:\n" + "Watch7,11 [Apple Watch Series 10 46mm case (GPS+Cellular)]\n" + "Watch7,10 [Apple Watch Series 10 42mm case (GPS+Cellular)]\n" + "Watch7,9 [Apple Watch Series 10 46mm case (GPS)]\n" + "Watch7,8 [Apple Watch Series 10 42mm case (GPS)]\n" + "Watch7,5 [Apple Watch Ultra 2 (49mm)]\n" + "Watch7,4 [Apple Watch Series 9 (45mm Cellular)]\n" + "Watch7,3 [Apple Watch Series 9 (41mm Cellular)]\n" + "Watch7,2 [Apple Watch Series 9 (45mm GPS)]\n" + "Watch7,1 [Apple Watch Series 9 (41mm GPS)]\n" + "Watch6,18 [Apple Watch Ultra (49mm)]\n" + "Watch6,17 [Apple Watch Series 8 (45mm Cellular)]\n" + "Watch6,16 [Apple Watch Series 8 (41mm Cellular)]\n" + "Watch6,15 [Apple Watch Series 8 (45mm GPS)]\n" + "Watch6,14 [Apple Watch Series 8 (41mm GPS)]\n" + "Watch6,13 [Apple Watch SE 2 (44mm Cellular)]\n" + "Watch6,12 [Apple Watch SE 2 (40mm Cellular)]\n" + "Watch6,11 [Apple Watch SE 2 (44mm GPS)]\n" + "Watch6,10 [Apple Watch SE 2 (40mm GPS)]\n" + "Watch6,9 [Apple Watch Series 7 (45mm Cellular)]\n" + "Watch6,8 [Apple Watch Series 7 (41mm Cellular)]\n" + "Watch6,7 [Apple Watch Series 7 (45mm GPS)]\n" + "Watch6,6 [Apple Watch Series 7 (41mm GPS)]\n" + "Watch6,4 [Apple Watch Series 6 (44mm Cellular)]\n" + "Watch6,3 [Apple Watch Series 6 (40mm Cellular)]\n" + "Watch6,2 [Apple Watch Series 6 (44mm GPS)]\n" + "Watch6,1 [Apple Watch Series 6 (40mm GPS)]\n" + "Watch5,12 [Apple Watch SE (44mm Cellular)]\n" + "Watch5,11 [Apple Watch SE (40mm Cellular)]\n\n" + "Unsupported:\n" + "Watch5,10 [Apple Watch SE (44mm GPS)]\n" + "Watch5,9 [Apple Watch SE (40mm GPS)]\n" + "Watch5,4 [Apple Watch Series 5 (44mm Cellular)]\n" + "Watch5,3 [Apple Watch Series 5 (40mm Cellular)]\n" + "Watch5,2 [Apple Watch Series 5 (44mm GPS)]\n" + "Watch5,1 [Apple Watch Series 5 (40mm GPS)]\n" + "Watch4,4 [Apple Watch Series 4 (44mm Cellular)]\n" + "Watch4,3 [Apple Watch Series 4 (40mm Cellular)]\n" + "Watch4,2 [Apple Watch Series 4 (44mm GPS)]\n" + "Watch4,1 [Apple Watch Series 4 (40mm GPS)]"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); final Matcher matcher = pattern.matcher(string); while (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i <= matcher.groupCount(); i++) { System.out.println("Group " + i + ": " + matcher.group(i)); } } } }

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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html