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

/
/
gm

Test String

Code Generator

Generated Code

package main import ( "regexp" "fmt" ) func main() { var re = regexp.MustCompile(`(?m)^(?<ROYAL_FLUSH>(A)(.) K\3 Q\3 J\3 T\3)|(?<STRAIGHT_FLUSH>(K)(.) Q\6 J\6 T\6 9\6|(Q)(.) J\8 T\8 9\8 8\8|(J)(.) T\10 9\10 8\10 7\10|(T)(.) 9\12 8\12 7\12 6\12|(9)(.) 8\14 7\14 6\14 5\14|(8)(.) 7\16 6\16 5\16 4\16|(7)(.) 6\18 5\18 4\18 3\18|(6)(.) 5\20 4\20 3\20 2\20|(A)(.) 5\22 4\22 3\22 2\22)|(?<FOUR_OF_A_KIND>.*(.). \24. \24. \24..*)|(?<FULL_HOUSE>(.). \26. (.). \27. \27.|(.). \28. \28. (.). \29.)|(?<FLUSH>(.)(.) .\32 .\32 .\32 .\32)|(?<STRAIGHT>(A). K. Q. J. T.|(K). Q. J. T. 9.|(Q). J. T. 9. 8.|(J). T. 9. 8. 7.|(T). 9. 8. 7. 6.|(9). 8. 7. 6. 5.|(8). 7. 6. 5. 4.|(7). 6. 5. 4. 3.|(6). 5. 4. 3. 2.|A. (5). 4. 3. 2.)|(?<THREE_OF_A_KIND>.*(.). \45. \45..*)|(?<TWO_PAIR>.*(.). \47. .*(.). \48..*)|(?<PAIR>.*(.). \50..*)|(?<HIGH_CARD>(.).*)$`) var str = `AH KH QC JS TS KH JS 8C 4S 4D KC 9C 8C 5C 4C KC KS 8D 4H 2H AC KS TS 9S 5S 7C 7S 7H 5S 3S KH QS JS TS 9H AS AD KH KC 3C KH KC 5S 5D 2C 6H 5C 4C 3C 2C 9H 8S 7S 6S 5H KD KC 8S 4S 3H JC JS JD JH 7H KD QH JH 8H 8S KH QH JH TH 9H KH 7C 7S 7H 2H AH QH JH TH 8S 3D 3H 2H 2C 2D KH KC 3S 3H 3D AD KD TH 9D 6S TH 9D 7D 6D 2D AH KH QH JH 8H KH JC JS JD JH 7C 6C 5C 4C 3C JC JS JD JH 6H AH KH QH JH TH TC 9C 8C 5C 3C 7S 5H 4S 3H 2C KS 9S 8D 4D 4S KS 9S 8S 5S 3S KH KC 5D 5S 3C AH AS KC JH 8S 3S 3H 3D 2H 2C AC AH AS KH QH JH TC 8C 6C 2S 6D 5D 4D 3D 2D 9D 8H 7H 6S 2C 4C 4H 3H 3S 2H` 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/