Regular Expressions 101

Save & Share

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

/
/
g

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 = "(\\s|\\S){0,40}\\\"([0-9]{1,3})\\\"\\;\\}"; final String string = "a:1:{s:2:\"gr\";s:3:\"214\";}\n" + "a:1:{s:2:\"gr\";s:3:\"188\";}\n" + "a:1:{s:2:\"gr\";s:3:\"213\";}\n" + "a:1:{s:2:\"gr\";s:3:\"169\";}\n" + "a:1:{s:2:\"gr\";s:3:\"219\";}\n" + "a:1:{s:2:\"gr\";s:3:\"221\";}\n" + "a:1:{s:2:\"gr\";s:3:\"211\";}\n" + "a:1:{s:2:\"gr\";s:3:\"184\";}\n" + "a:1:{s:2:\"gr\";s:3:\"191\";}\n" + "a:1:{s:2:\"gr\";s:2:\"16\";}\n" + "a:1:{s:2:\"gr\";s:3:\"127\";}\n" + "a:1:{s:2:\"gr\";s:3:\"217\";}\n" + "a:1:{s:2:\"gr\";s:3:\"200\";}\n" + "a:1:{s:2:\"gr\";s:3:\"182\";}\n" + "a:1:{s:2:\"gr\";s:3:\"128\";}\n" + "a:1:{s:2:\"gr\";s:2:\"17\";}\n" + "a:1:{s:2:\"gr\";s:3:\"163\";}\n" + "a:1:{s:2:\"gr\";s:3:\"212\";}\n" + "a:1:{s:2:\"gr\";s:3:\"166\";}\n" + "a:1:{s:2:\"gr\";s:2:\"94\";}\n" + "a:1:{s:2:\"gr\";s:2:\"83\";}\n" + "a:1:{s:2:\"gr\";s:2:\"27\";}\n" + "a:1:{s:2:\"gr\";s:2:\"28\";}\n" + "a:1:{s:2:\"gr\";s:3:\"167\";}\n" + "a:1:{s:2:\"gr\";s:3:\"168\";}\n" + "a:1:{s:2:\"gr\";s:3:\"202\";}\n" + "a:1:{s:2:\"gr\";s:1:\"7\";}\n" + "a:1:{s:2:\"gr\";s:3:\"129\";}\n" + "a:1:{s:2:\"gr\";s:3:\"183\";}\n" + "a:1:{s:2:\"gr\";s:2:\"26\";}\n" + "a:1:{s:2:\"gr\";s:3:\"185\";}\n" + "a:1:{s:2:\"gr\";s:3:\"175\";}\n" + "a:1:{s:2:\"gr\";s:2:\"29\";}\n" + "a:1:{s:2:\"gr\";s:3:\"209\";}\n" + "a:1:{s:2:\"gr\";s:3:\"177\";}\n" + "a:1:{s:2:\"gr\";s:3:\"178\";}\n" + "a:1:{s:2:\"gr\";s:2:\"24\";}\n" + "a:1:{s:2:\"gr\";s:3:\"225\";}\n" + "a:1:{s:2:\"gr\";s:3:\"224\";}\n" + "a:1:{s:2:\"gr\";s:2:\"57\";}\n" + "a:1:{s:2:\"gr\";s:2:\"18\";}\n" + "a:1:{s:2:\"gr\";s:3:\"208\";}\n" + "a:1:{s:2:\"gr\";s:3:\"193\";}\n" + "a:1:{s:2:\"gr\";s:2:\"33\";}\n" + "a:1:{s:2:\"gr\";s:2:\"10\";}\n" + "a:1:{s:2:\"gr\";s:2:\"11\";}\n" + "a:1:{s:2:\"gr\";s:2:\"12\";}\n" + "a:1:{s:2:\"gr\";s:3:\"173\";}\n" + "a:1:{s:2:\"gr\";s:2:\"13\";}\n" + "a:1:{s:2:\"gr\";s:2:\"14\";}\n" + "a:1:{s:2:\"gr\";s:1:\"9\";}\n" + "a:1:{s:2:\"gr\";s:2:\"15\";}\n" + "a:1:{s:2:\"gr\";s:3:\"195\";}\n" + "a:1:{s:2:\"gr\";s:3:\"130\";}\n" + "a:1:{s:2:\"gr\";s:2:\"25\";}\n" + "a:1:{s:2:\"gr\";s:2:\"50\";}\n" + "a:1:{s:2:\"gr\";s:3:\"131\";}\n" + "a:1:{s:2:\"gr\";s:2:\"96\";}\n" + "a:1:{s:2:\"gr\";s:2:\"19\";}\n" + "a:1:{s:2:\"gr\";s:3:\"107\";}\n" + "a:1:{s:2:\"gr\";s:3:\"116\";}\n" + "a:1:{s:2:\"gr\";s:3:\"364\";}\n" + "a:1:{s:2:\"gr\";s:3:\"194\";}\n" + "a:1:{s:2:\"gr\";s:2:\"44\";}\n" + "a:1:{s:2:\"gr\";s:3:\"171\";}\n" + "a:1:{s:2:\"gr\";s:3:\"172\";}\n" + "a:1:{s:2:\"gr\";s:3:\"170\";}\n" + "a:1:{s:2:\"gr\";s:2:\"20\";}\n" + "a:1:{s:2:\"gr\";s:2:\"95\";}\n" + "a:1:{s:2:\"gr\";s:2:\"84\";}\n" + "a:1:{s:2:\"gr\";s:2:\"22\";}\n" + "a:1:{s:2:\"gr\";s:2:\"23\";}\n" + "a:1:{s:2:\"gr\";s:2:\"67\";}\n" + "a:1:{s:2:\"gr\";s:3:\"118\";}\n" + "a:1:{s:2:\"gr\";s:2:\"97\";}\n" + "a:1:{s:2:\"gr\";s:1:\"6\";}\n" + "a:1:{s:2:\"gr\";s:3:\"365\";}\n" + "a:1:{s:2:\"gr\";s:3:\"190\";}\n" + "a:1:{s:2:\"gr\";s:2:\"82\";}\n" + "a:1:{s:2:\"gr\";s:2:\"42\";}\n" + "a:1:{s:2:\"gr\";s:2:\"74\";}\n" + "a:1:{s:2:\"gr\";s:2:\"76\";}\n" + "a:1:{s:2:\"gr\";s:2:\"73\";}\n" + "a:1:{s:2:\"gr\";s:2:\"78\";}\n" + "a:1:{s:2:\"gr\";s:2:\"68\";}\n" + "a:1:{s:2:\"gr\";s:3:\"207\";}\n" + "a:1:{s:2:\"gr\";s:3:\"197\";}\n" + "a:1:{s:2:\"gr\";s:2:\"77\";}\n" + "a:1:{s:2:\"gr\";s:2:\"46\";}\n" + "a:1:{s:2:\"gr\";s:2:\"51\";}\n" + "a:1:{s:2:\"gr\";s:3:\"206\";}\n" + "a:1:{s:2:\"gr\";s:3:\"165\";}\n" + "a:1:{s:2:\"gr\";s:2:\"60\";}\n" + "a:1:{s:2:\"gr\";s:2:\"61\";}\n" + "a:1:{s:2:\"gr\";s:2:\"62\";}\n" + "a:1:{s:2:\"gr\";s:3:\"187\";}\n" + "a:1:{s:2:\"gr\";s:3:\"176\";}\n" + "a:1:{s:2:\"gr\";s:3:\"196\";}\n" + "a:1:{s:2:\"gr\";s:3:\"223\";}\n" + "a:1:{s:2:\"gr\";s:3:\"117\";}\n" + "a:1:{s:2:\"gr\";s:2:\"98\";}\n" + "a:1:{s:2:\"gr\";s:2:\"47\";}\n" + "a:1:{s:2:\"gr\";s:3:\"198\";}\n" + "a:1:{s:2:\"gr\";s:2:\"45\";}\n" + "a:1:{s:2:\"gr\";s:3:\"203\";}\n" + "a:1:{s:2:\"gr\";s:3:\"205\";}\n" + "a:1:{s:2:\"gr\";s:3:\"201\";}\n" + "a:1:{s:2:\"gr\";s:3:\"115\";}\n" + "a:1:{s:2:\"gr\";s:2:\"58\";}\n" + "a:1:{s:2:\"gr\";s:3:\"204\";}\n" + "a:1:{s:2:\"gr\";s:3:\"132\";}\n" + "a:1:{s:2:\"gr\";s:2:\"48\";}\n" + "a:1:{s:2:\"gr\";s:2:\"49\";}\n" + "a:1:{s:2:\"gr\";s:2:\"99\";}\n" + "a:1:{s:2:\"gr\";s:3:\"594\";}\n" + "a:1:{s:2:\"gr\";s:3:\"585\";}\n" + "a:1:{s:2:\"gr\";s:3:\"368\";}\n" + "a:1:{s:2:\"gr\";s:2:\"81\";}\n" + "a:1:{s:2:\"gr\";s:2:\"53\";}\n" + "a:1:{s:2:\"gr\";s:2:\"52\";}\n" + "a:1:{s:2:\"gr\";s:3:\"180\";}\n" + "a:1:{s:2:\"gr\";s:3:\"181\";}\n" + "a:1:{s:2:\"gr\";s:3:\"179\";}\n" + "a:1:{s:2:\"gr\";s:3:\"164\";}\n" + "a:1:{s:2:\"gr\";s:3:\"186\";}\n" + "a:1:{s:2:\"gr\";s:3:\"174\";}\n" + "a:1:{s:2:\"gr\";s:3:\"199\";}\n" + "a:1:{s:2:\"gr\";s:3:\"210\";}\n" + "a:1:{s:2:\"gr\";s:3:\"369\";}\n" + "a:1:{s:2:\"gr\";s:3:\"370\";}\n" + "a:1:{s:2:\"gr\";s:3:\"371\";}\n" + "a:1:{s:2:\"gr\";s:3:\"372\";}\n" + "a:1:{s:2:\"gr\";s:3:\"373\";}\n" + "a:1:{s:2:\"gr\";s:3:\"374\";}\n" + "a:1:{s:2:\"gr\";s:3:\"375\";}"; final Pattern pattern = Pattern.compile(regex); 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