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

/
/
gmi

Test String

Code Generator

Generated Code

use strict; my $str = 'Xiaomi Pocophone F1 Google Pixel 4 XL Samsung Galaxy S22 Plus 5G Samsung Galaxy Tab A 9.7 Samsung Tab E Huawei Y9 2019 Samsung Galaxy Tab S8 Samsung Tab E 9.6 Samsung Galaxy S8 Google Pixel 2 Samsung Galaxy A10 Samsung Galaxy A51 LG Q6 Huawei P9 Samsung Galaxy A71 5G ZTE Axon 7 Samsung Galaxy S20 Ultra LG Q Stylo 4 Moto Z2 Force Samsung Galaxy S21 5G ZTE Axon 7 Google Pixel 3a XL Samsung Galaxy S6 Edge Sony Xperia XZ OnePlus 9 Pro Samsung Galaxy S8+ Samsung Galaxy Note 20 Ultra 5G LG V30 Motorola Moto Z OnePlus 5T Samsung Galaxy S6 Edge Samsung Galaxy M20 OnePlus 9 Samsung Galaxy A02 Samsung Galaxy S7 Mason D450B Samsung Galaxy S22 5G Google Pixel 4a Samsung Galaxy Tab A 10.1 2016 Samsung Galaxy Note 8 Asus Google Nexus 7 (2013) Samsung Galaxy A30 Google Pixel 4 XL Vivo X21 Samsung Galaxy S10e Samsung Galaxy S10 Samsung Galaxy S21 Plus 5G OnePlus Nord N200 5G Google Pixel 4 XL Samsung Galaxy A9 2018 Samsung Galaxy A51 Motorola Moto G Stylus 2021 Google Pixel 4 Huawei Honor 9 Samsung Galaxy S6 Edge+ Samsung Galaxy A20e Mason G450A1 Xiaomi Mi MIX 2 Samsung Galaxy Tab A7 Google Pixel 5a Google Pixel 6 Pro Samsung Galaxy A21 Samsung Galaxy Note 20 5G HTC One A9 Huawei Honor 8 Samsung Galaxy S6 Edge+ Google Pixel 2 XL Samsung Galaxy S8+ Nokia 7.1 Samsung Galaxy S20 Plus Samsung Galaxy A3 2017 LG K10 HTC Desire 12 Samsung Galaxy A5 (2017) Huawei P30 Lite LG V40 OnePlus 6T Google Pixel 3 XL Google Pixel C Motorola Moto G5 Plus Samsung Galaxy S20 Samsung Galaxy A31 Google Pixel 3 Sony Z5 Premium Sony Xperia Z1 LG Phoenix 2 Samsung Galaxy Tab S6 Samsung Galaxy J7 2016 Honeywell CK65 Samsung Galaxy A5 HTC 10 Sony Xperia 10 Google Pixel 3a XL Sony Xperia 5 Samsung Galaxy A6 2018 Samsung Galaxy S9 Samsung Galaxy S5 Google Pixel XL LG G7 Thinq Motorola Moto X Play Huawei P30 Lite Samsung Galaxy S10+ Samsung Galaxy Tab S2 Samsung Galaxy Tab S8 Plus LG K30 LG V30+ Thinq Samsung Galaxy A80 OnePlus 3T Samsung Galaxy S22 Ultra 5G Huawei Mate 9 Samsung Galaxy Note 20 Ultra 5G OnePlus 3 OnePlus 7 Pro Nokia 8 Samsung Galaxy Z Fold 2 5G OnePlus 6 Samsung Galaxy Tab S5e Samsung Galaxy A50 Samsung Galaxy S21 Ultra 5G LG Stylo 6 Google Pixel 3 Sony Xperia Z3 Compact Xiaomi MI 6 LG V20 Google Pixel 5 Motorola Moto G Power (2021) Lenovo Tab 3 Pro Motorola Moto G6 Essential PH-1 Samsung Galaxy Note 9 Samsung Galaxy S10e Samsung Galaxy A8 2018 Samsung Galaxy A10e Samsung Galaxy Note 5 Samsung Galaxy Fold 5G Samsung Galaxy Note 4 Samsung Galaxy S21 5G Samsung Galaxy Tab S7 Motorola One Vision Samsung Galaxy Note 10+ LG G8 ThinQ Amazon Kindle Fire HD 8 Motorola Moto G7 Samsung Galaxy Tab S7 Plus Samsung Galaxy Z Flip LG G6 Samsung Galaxy S7 Edge Samsung Galaxy Tab S8 Ultra Google Pixel 6 Pro Huawei P10 Huawei P20 Samsung Galaxy Note 5 OnePlus 8 Pro Amazon Kindle Fire HD 8 (2020) Samsung Galaxy S6 Xiaomi Redmi Note 9 Motorola Nexus 6 Motorola Moto G6 Plus Vivo V9 Samsung Galaxy Tab S4 Samsung Galaxy S10 Motorola Moto X (2nd gen) Amazon Kindle Fire HD 10 (2019) OnePlus 7T OnePlus 8 Samsung Galaxy Xcover 3 Xiaomi Redmi 9 Sony Xperia XZ1 ZTE Blade V7 lite Huawei P30 Pro Samsung Galaxy Tab S4 10.5 Google Pixel 6 Amazon Kindle Fire HD 7 Huawei P20 Pro Motorola Moto Z Play Huawei Mate 10 Pro OnePlus 5 Google Pixel 3 XL Google Pixel 3a Samsung Galaxy Note 10 Samsung Galaxy Tab S3'; my $regex = qr/.*nexus.*/mip; if ( $str =~ /$regex/g ) { print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n"; # print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n"; # print "Capture Group 2 is $2 ... and so on\n"; } # ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p' # Named capture groups can be called via $+{name}

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 Perl, please visit: http://perldoc.perl.org/perlre.html