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

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