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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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 = "iPhone [6-7]"; final String string = "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"; 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