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

re = /([0-7]\d{2}(" "|-|\.)?\d{2}(?(2)(" "|-|\.))\d{4})/m str = ' Name SSN Gender Birthday Age Address(street Address, State Zip Code) Walsh Muhammad 405711626 male 19960508 27 313 Austen Wall Suite 736 East Adeline, KY 19160-6708 Ankunding Noel 579-28-4539 male 19860626 38 5353 Anjali Springs Annabellberg, DC 51532 Bruen Kelly 003-70-9850 female 19860924 37 1703 Adolfo Hill North Avatown, NH 20701-1024 VonRueden Pearline 520-76-6341 female 19830831 41 890 O\'Conner Viaduct Juanaside, WY 98001 Harris Eryn 400-36-0787 female 19720608 52 154 Michelle Plains North Maidaside, KY 61013 Murphy Betsy 400-59-2780 female 19840213 40 936 Douglas Burg Jairomouth, KY 44386-4279 Gusikowski Crystel 508.06.-6325 female 19950819 29 841 Dameon Place Nitzscheview, NE 46251-3648 Grimes Ivy 670-05.5398 female 19780507 45 71345 Fritsch Freeway East Kellyfort, GA 64987 Balistreri Xzavier 232.09-8803 male 19830831 41 5441 Vincenzo Ways Apt. 491 West Bessieshire, WV 85827-5053 Blanda Pamela 396-09-2848 female 19751208 49 1751 Jana Walks Apt. 139 Paulinetown, WI 27274-2921 Hilll London 547-45-3802 male 19760618 48 2133 Ruby Forest South Masonhaven, CA 97443-5496 Will Dale 364-96-7590 male 19940424 30 39099 Hardy Street West Kasey, MI 35581 Muller Scarlett 646-38-0484 female 19981020 25 51954 Connelly Bypass East Nathaniel, UT 96705-2438 Rowe Angie 145-20-9660 female 19881002 35 73566 Maureen Station Karleymouth, NJ 69784-4470 Mitchell Tad 028-54-3165 male 19831101 40 962 Collins Run Port Destiny, MA 59924 Moen Orland 388-15-8827 male 19740629 50 5369 Gabriel Locks Apt. 623 Marvinview, WI 34399-9949 Erdman Tabitha 221-82-2804 female 19781219 46 4874 Roberto Union Suite 252 Dagmarport, DE 93676-9058 Macejkovic Nick 247-96-5798 male 19910925 32 1574 Glover Lights Suite 639 Blanchestad, SC 78776-7217 Feest Lance 512-66-3053 male 19910320 32 998 Sporer Mountain Apt. 664 Port Deangelo, KS 77731 Kuhic Peter 315-30-2791 male 19850807 39 405 Korey Forges Lake Alvena, IN 86152' # Print the match result str.scan(re) do |match| puts match.to_s end

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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html