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

$re = '/iPhone1[1-7],\d|iPad((7,1[12])|(8,\d+)|1[1-6],\d+)|Watch(5,1[12]|[6-7],\d+)/m'; $str = 'https://support.apple.com/guide/iphone/iphone-models-compatible-with-ios-18-iphe3fa5df43/ios https://support.apple.com/guide/ipad/ipad-models-compatible-with-ipados-18-ipad213a25b2/ipados https://www.apple.com/watchos/watchos-11/ Published Date: June 10, 2024 Updated November 1, 2024 Verification: https://regex101.com/r/0UDJHk/7 1) Exact regex — Matches major model identifier numbers based on Jamf\'s hardware model identifiers list (more accurate): ^iPhone1[1-7],\\d|iPad((7,1[12])|(8,\\d+)|1[1-6],\\d+)|Watch(5,1[12]|[6-7],\\d+)$ 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). ^iPhone1[1-9],\\d+|iPad((7,1[12])|(8,\\d+)|1[1-9],\\d+)|Watch(5,1[12]|[6-9],\\d+)$ Either regex will match any of the supported following model identifiers: iPhone https://hw-model-names.services.jamfcloud.com/1/mobileDeviceModels.xml Exact regex: ^iPhone1[1-7],\\d$ Current or higher regex: ^iPhone1[1-9],\\d$ Supported: iPhone17,4 [iPhone 16 Plus] iPhone17,3 [iPhone 16] iPhone17,2 [iPhone 16 Pro Max] iPhone17,1 [iPhone 16 Pro] iPhone16,2 [iPhone 15 Pro Max] iPhone16,1 [iPhone 15 Pro] iPhone15,5 [iPhone 15 Plus] iPhone15,4 [iPhone 15] iPhone15,3 [iPhone 14 Pro Max] iPhone15,2 [iPhone 14 Pro] iPhone14,8 [iPhone 14 Plus] iPhone14,7 [iPhone 14] iPhone14,6 [iPhone SE (3rd Generation)] iPhone14,2 [iPhone 13 Pro] iPhone14,3 [iPhone 13 Pro Max] iPhone14,4 [iPhone 13 mini] iPhone14,5 [iPhone 13] iPhone13,4 [iPhone 12 Pro Max] iPhone13,3 [iPhone 12 Pro] iPhone13,2 [iPhone 12] iPhone13,1 [iPhone 12 mini] iPhone12,8 [iPhone SE (2nd Generation)] iPhone12,5 [iPhone 11 Pro Max] iPhone12,3 [iPhone 11 Pro] iPhone12,1 [iPhone 11] iPhone11,8 [iPhone XR] iPhone11,6 [iPhone XS Max] iPhone11,4 [iPhone XS Max] iPhone11,2 [iPhone XS] Unsupported: iPhone10,6 (iPhone X) iPhone10,5 (iPhone 8 Plus) iPhone10,4 (iPhone 8) iPhone10,3 (iPhone X) iPhone10,2 (iPhone 8 Plus) iPhone10,1 (iPhone 8) iPhone9,4 (iPhone 7 Plus) iPhone9,3 (iPhone 7) iPhone9,2 (iPhone 7 Plus) iPhone9,1 (iPhone 7) iPhone8,4 (iPhone SE) iPhone8,2 (iPhone 6S Plus) iPhone8,1 (iPhone 6S) iPhone7,2 (iPhone 6) iPhone7,1 (iPhone 6 Plus) iPhone6,2 (iPhone 5S (CDMA)) iPhone6,1 (iPhone 5S (GSM)) iPhone5,4 (iPhone 5C (CDMA)) iPhone5,3 (iPhone 5C (GSM)) iPhone5,2 (iPhone 5 (CDMA)) iPhone5,1 (iPhone 5 (GSM)) iPhone4,1 (iPhone 4S) iPhone3,3 (iPhone 4 (CDMA)) iPhone3,1 (iPhone 4 (GSM)) iPhone2,1 (iPhone 3GS) iPhone1,2 (iPhone 3G) iPhone1,1 (iPhone (Original)) --------------------------------------------------- All supported iPads Exact regex: ^iPad(7,1[12]|(8|1[1-6]),\\d+)$ Current or higher regex: Not available --------------------------------------------------- iPad https://hw-model-names.services.jamfcloud.com/1/mobileDeviceModels.xml Exact regex: ^iPad(7,(1[12])|11,[67]|12,[12]|13,1[89])$ Current or higher regex: Not available Supported: iPad13,19 [iPad 10th Generation (Wi-Fi/Cellular)] iPad13,18 [iPad 10th Generation (Wi-Fi)] iPad12,2 [iPad 9th generation (Cellular)] iPad12,1 [iPad 9th generation (Wi-Fi)] iPad11,7 [iPad 8th generation (Cellular)] iPad11,6 [iPad 8th generation (Wi-Fi)] iPad7,12 [iPad 7th Generation (Cellular)] iPad7,11 [iPad 7th Generation (Wi-Fi)] Unsupported: iPad7,6 [iPad 6th Generation (Cellular)] iPad7,5 [iPad 6th Generation (Wi-Fi)] iPad6,12 [iPad 5th Generation (Cellular)] iPad6,11 [iPad 5th Generation (Wi-Fi)] iPad3,6 [iPad 4th Generation (GSM)] iPad3,5 [iPad 4th Generation (CDMA)] iPad3,4 [iPad 4th Generation (Wi-Fi)] iPad3,3 [iPad 3rd Generation (GSM)] iPad3,2 [iPad 3rd Generation (CDMA)] iPad3,1 [iPad 3rd Generation (Wi-Fi)] iPad2,4 [iPad 2 (Wi-Fi)] iPad2,3 [iPad 2 (CDMA)] iPad2,2 [iPad 2 (GSM)] iPad2,1 [iPad 2 (Wi-Fi)] iPad1,2 [iPad (3G)] iPad1,1 [iPad (Original)] --------------------------------------------------- iPad Air https://hw-model-names.services.jamfcloud.com/1/mobileDeviceModels.xml Exact regex: ^iPad1((1,[34])|3,(1$|1[67]|2)+|4,(1[01]|8|9))$ Current or higher regex: Not available Supported: iPad14,11 [iPad Air 13-inch (M2)] iPad14,10 [iPad Air 13-inch (M2)] iPad14,9 [iPad Air 11-inch (M2)] iPad14,8 [iPad Air 11-inch (M2)] iPad13,17 [iPad Air 5th generation (Cellular)] iPad13,16 [iPad Air 5th generation (Wi-Fi)] iPad13,2 [iPad Air 4th generation (Cellular)] iPad13,1 [iPad Air 4th generation (Wi-Fi)] iPad11,4 [iPad Air 3rd generation (Cellular)] iPad11,3 [iPad Air 3rd generation (Wi-Fi)] Unsupported: iPad5,4 (iPad Air 2 (CDMA)) iPad5,3 (iPad Air 2 (Wi-Fi)) iPad4,2 (iPad Air (GSM)) iPad4,1 (iPad Air (Wi-Fi)) --------------------------------------------------- iPad mini https://hw-model-names.services.jamfcloud.com/1/mobileDeviceModels.xml Exact regex: ^iPad1(1,[12]|4,[12])$ Current or higher regex: Not available Supported: iPad14,2 [iPad mini 6th generation (Cellular)] iPad14,1 [iPad mini 6th generation (Wi-Fi)] iPad11,2 [iPad mini 5th generation (Cellular)] iPad11,1 [iPad mini 5th generation (Wi-Fi)] Unsupported: iPad5,2 (iPad mini 4 (GSM)) iPad5,1 (iPad mini 4 (Wi-Fi)) iPad4,8 (iPad mini 3 (GSM)) iPad4,7 (iPad mini 3 (Wi-Fi)) iPad4,5 (iPad mini 2nd Generation (GSM)) iPad4,4 (iPad mini 2nd Generation (Wi-Fi)) iPad2,7 (iPad mini (CDMA)) iPad2,6 (iPad mini (GSM)) iPad2,5 (iPad mini (Wi-Fi Only)) --------------------------------------------------- iPad Pro https://hw-model-names.services.jamfcloud.com/1/mobileDeviceModels.xml Exact regex: ^iPad((8,[1-4]$|8,[1-9]\\d?)|13,([4-9]|1[01])|14,[3456]|16,[3-6])$ Current or higher regex: Not available Supported: iPad16,6 [iPad Pro 13-inch (M4)] iPad16,5 [iPad Pro 13-inch (M4)] iPad16,4 [iPad Pro 11-inch (M4)] iPad16,3 [iPad Pro 11-inch (M4)] iPad14,6 [iPad Pro (12.9-inch Wi-Fi/Cellular) (6th generation)] iPad14,5 [iPad Pro (12.9-inch) (6th generation)] iPad14,4 [iPad Pro (11-inch Wi-Fi/Cellular) (4th generation)] iPad14,3 [iPad Pro (11-inch) (4th generation)] iPad13,11 [iPad Pro (12.9-inch) (5th generation)] iPad13,10 [iPad Pro (12.9-inch) (5th generation)] iPad13,9 [iPad Pro (12.9-inch) (5th generation)] iPad13,8 [iPad Pro (12.9-inch) (5th generation)] iPad13,7 [iPad Pro (11-inch) (3rd generation)] iPad13,6 [iPad Pro (11-inch) (3rd generation)] iPad13,5 [iPad Pro (11-inch) (3rd generation)] iPad13,4 [iPad Pro (11-inch) (3rd generation)] iPad8,12 [iPad Pro (12.9-inch Cellular) (4th Generation)] iPad8,11 [iPad Pro (12.9-inch Wi-Fi) (4th Generation)] iPad8,10 [iPad Pro (11-inch Cellular) (2nd Generation)] iPad8,9 [iPad Pro (11-inch Wi-Fi) (2nd Generation)] iPad8,8 [iPad Pro (12.9-inch 1TB Cellular)] iPad8,7 [iPad Pro (12.9-inch Cellular) (3rd Generation)] iPad8,6 [iPad Pro (12.9-inch 1TB Wi-Fi)] iPad8,5 [iPad Pro (12.9-inch Wi-Fi) (3rd Generation)] iPad8,4 [iPad Pro (11-inch 1TB Cellular)] iPad8,3 [iPad Pro (11-inch Cellular)] iPad8,2 [iPad Pro (11-inch 1TB Wi-Fi)] iPad8,1 [iPad Pro (11-inch Wi-Fi)] Unsupported: iPad6,8 (iPad Pro (12.9-inch Cellular)) iPad6,7 (iPad Pro (12.9-inch Wi-Fi)) iPad6,4 (iPad Pro (9.7-inch Cellular)) iPad6,3 (iPad Pro (9.7-inch Wi-Fi)) --------------------------------------------------- Apple Watch https://hw-model-names.services.jamfcloud.com/1/mobileDeviceModels.xml Exact regex: ^Watch(5,1[12]|[6-7],\\d+)$ Current or higher regex: ^Watch(5,1[12]|([6-9]|1[0-9]),\\d+)$ Supported: Watch7,11 [Apple Watch Series 10 46mm case (GPS+Cellular)] Watch7,10 [Apple Watch Series 10 42mm case (GPS+Cellular)] Watch7,9 [Apple Watch Series 10 46mm case (GPS)] Watch7,8 [Apple Watch Series 10 42mm case (GPS)] Watch7,5 [Apple Watch Ultra 2 (49mm)] Watch7,4 [Apple Watch Series 9 (45mm Cellular)] Watch7,3 [Apple Watch Series 9 (41mm Cellular)] Watch7,2 [Apple Watch Series 9 (45mm GPS)] Watch7,1 [Apple Watch Series 9 (41mm GPS)] Watch6,18 [Apple Watch Ultra (49mm)] Watch6,17 [Apple Watch Series 8 (45mm Cellular)] Watch6,16 [Apple Watch Series 8 (41mm Cellular)] Watch6,15 [Apple Watch Series 8 (45mm GPS)] Watch6,14 [Apple Watch Series 8 (41mm GPS)] Watch6,13 [Apple Watch SE 2 (44mm Cellular)] Watch6,12 [Apple Watch SE 2 (40mm Cellular)] Watch6,11 [Apple Watch SE 2 (44mm GPS)] Watch6,10 [Apple Watch SE 2 (40mm GPS)] Watch6,9 [Apple Watch Series 7 (45mm Cellular)] Watch6,8 [Apple Watch Series 7 (41mm Cellular)] Watch6,7 [Apple Watch Series 7 (45mm GPS)] Watch6,6 [Apple Watch Series 7 (41mm GPS)] Watch6,4 [Apple Watch Series 6 (44mm Cellular)] Watch6,3 [Apple Watch Series 6 (40mm Cellular)] Watch6,2 [Apple Watch Series 6 (44mm GPS)] Watch6,1 [Apple Watch Series 6 (40mm GPS)] Watch5,12 [Apple Watch SE (44mm Cellular)] Watch5,11 [Apple Watch SE (40mm Cellular)] Unsupported: Watch5,10 [Apple Watch SE (44mm GPS)] Watch5,9 [Apple Watch SE (40mm GPS)] Watch5,4 [Apple Watch Series 5 (44mm Cellular)] Watch5,3 [Apple Watch Series 5 (40mm Cellular)] Watch5,2 [Apple Watch Series 5 (44mm GPS)] Watch5,1 [Apple Watch Series 5 (40mm GPS)] Watch4,4 [Apple Watch Series 4 (44mm Cellular)] Watch4,3 [Apple Watch Series 4 (40mm Cellular)] Watch4,2 [Apple Watch Series 4 (44mm GPS)] Watch4,1 [Apple Watch Series 4 (40mm GPS)]'; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); // Print the entire match result var_dump($matches);

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 PHP, please visit: http://php.net/manual/en/ref.pcre.php