Save & Share

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
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
Processing...

Test String

Code Generator

Generated Code

import re regex = re.compile(r"^(?<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>(.).*)$", flags=re.MULTILINE) test_str = ("AH KH QC JS TS\n" "KH JS 8C 4S 4D\n" "KC 9C 8C 5C 4C\n" "KC KS 8D 4H 2H\n" "AC KS TS 9S 5S\n" "7C 7S 7H 5S 3S\n" "KH QS JS TS 9H\n" "AS AD KH KC 3C\n" "KH KC 5S 5D 2C\n" "6H 5C 4C 3C 2C\n" "9H 8S 7S 6S 5H\n" "KD KC 8S 4S 3H\n" "JC JS JD JH 7H\n" "KD QH JH 8H 8S\n" "KH QH JH TH 9H\n" "KH 7C 7S 7H 2H\n" "AH QH JH TH 8S\n" "3D 3H 2H 2C 2D\n" "KH KC 3S 3H 3D\n" "AD KD TH 9D 6S\n" "TH 9D 7D 6D 2D\n" "AH KH QH JH 8H\n" "KH JC JS JD JH\n" "7C 6C 5C 4C 3C\n" "JC JS JD JH 6H\n" "AH KH QH JH TH\n" "TC 9C 8C 5C 3C\n" "7S 5H 4S 3H 2C\n" "KS 9S 8D 4D 4S\n" "KS 9S 8S 5S 3S\n" "KH KC 5D 5S 3C\n" "AH AS KC JH 8S\n" "3S 3H 3D 2H 2C\n" "AC AH AS KH QH\n" "JH TC 8C 6C 2S\n" "6D 5D 4D 3D 2D\n" "9D 8H 7H 6S 2C\n" "4C 4H 3H 3S 2H") matches = regex.finditer(test_str) for match_num, match in enumerate(matches, start=1): print(f"Match {match_num} was found at {match.start()}-{match.end()}: {match.group()}") for group_num, group in enumerate(match.groups(), start=1): print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")

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 Python, please visit: https://docs.python.org/3/library/re.html