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
No Match

r"
"
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 = "\\d{1,} ([a-zA-Z][a-zA-Z0-9]{0,15}) = (\\-?([a-zA-Z][a-zA-Z0-9]{0,15}|[0-9]{1,}) (\\+|\\-|\\*|\\/) \\-?([a-zA-Z][a-zA-Z0-9]{0,15}|[0-9]{1,})|\\-?([a-zA-Z][a-zA-Z0-9]{0,15}|[0-9]{1,}))$"; final String string = "1 EAr = 597 / -39\n" + "2 HmRP = 2741 + 11\n" + "3 sM = 581 - sM\n" + "4 PhybLRr5MQBJ = PhybLRr5MQBJ / 790\n" + "5 0ZL = 0ZL * -324\n" + "6 x8cYcKIald x8cYcKIald - 55\n" + "7 ZmgtleHAEeeM = 2598 + \n" + "8 uDM49CqM # -4768 * uDM49CqM\n" + "9 hdKM5gcTnhFg5EH = 272 + qq8d\n" + "10 4DDUktOAQfGsBjB1 = 49 - 4DDUktOAQfGsBjB1\n" + "11 xhy2eVHuaC3 = -50`8125\n" + "12 nzp60O = nzp60O * 273\n" + "13 kqThXnQ = -510 + kqThXnQ\n" + "14 waZ3dysjsj=waZ3dysjsj\n" + "15 0ltqh8pZUhY6KM = -7068\n" + "16 n98IKfQ0KhR4Ogq = 78 * 2637\n" + "17 wpj = wpj wpj\n" + "18 vLnyRzQQKmc0NVU = vLnyRzQQKmc0NVU - vLnyRzQQKmc0NVU\n" + "19 U4ZwSPYGFKnmqpn = -7015 + U4ZwSPYGFKnmqpn\n" + "20 h25bRmbGpKw4X = -71\n" + "21 N1sLOGPryc4A = 728 * N1sLOGPryc4A\n" + "22 j4UcrnDnR0Aj = 6844\n" + "23 qtMieAJ = qtMieAJ * i\n" + "24 V7rqZ2FFN7lj = V7rqZ2FFN7lj(5897\n" + "25 kMGA34oRhAn78Eh = kMGA34oRhAn78Eh,-29\n" + "26 taVAdRtz3Y = taVAdRtz3Y + 418-\n" + "27 pIgMkrSRYdhJm9 = pIgMkrSRYdhJm9 pIgMkrSRYdhJm9\n" + "28 3bB5T7QCQ = 281\n" + "29 U3BuJ = -4695 / -106\n" + "30 gX4Qvq1p3kdYQ0G = -79 + gX4Qvq1p3kdYQ0G\n" + "31 NpsotxU2vyDvS7By = NpsotxU2vyDvS7By + \n" + "32 S9gibae = 601 - -7778\n" + "33 li ! li * -844\n" + "34 bG14MTpgtsqrM81 = bG14MTpgtsqrM81 - 48\n" + "35 Qkt3o7sQ=Qkt3o7sQ\n" + "36 nHeIDT7mMLaF = nHeIDT7mMLaF\n" + "37 sJsw1759 = sJsw1759 + sJsw1759\n" + "38 oBnw09 = 53@oBnw09\n" + "39 axLq = axLq\n" + "40 L4gNW62VVgP = -950\n" + "41 xKLg00YtISqDTYl = -9432\n" + "42 LOTLlJjEVnefSGl = LOTLlJjEVnefSGl * LOTLlJjEVnefSGl\n" + "43 hxC1DY0xwaY = hxC1DY0xwaY / hxC1DY0xwaY\n" + "44 cAHDrb = -5613 -4948\n" + "45 O3RuYn74ES -36 - -1709\n" + "46 DOiOK0R2e3a9TSoL = 710 - DOiOK0R2e3a9TSoL\n" + "47 NSgi3k5kh0sXmB = NSgi3k5kh0sXmB\n" + "48 yaZuVW5m = 954\n" + "49 gush = -211 * 0114\n" + "50 OMPLI3wO4ZSSqvK = OMPLI3wO4ZSSqvK -73"; 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