Regular Expressions 101

Save & Share

  • Regex Version: ver. 13
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

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

Substitution

Processing...

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 = "(,\"\"38,602\"\",)\n"; final String string = "Benjamin Sosa 1 (825) 828-0003\n" + "Wanda's Vocal Coaching 207-LARYNX-1\n" + "Taste of Mexico Restaurant 418TAMALE9\n" + "Hope Tyler 515.720.3628\n" + "Bernadette Stanley 226-850-6891\n" + "Omar Sullivan 1 (970) 641▪5436\n" + "Tamera Norton 1*770*285*0559\n" + "Marcy Albert (527) 664-4544\n" + "Carl Velez (730) 384-4328\n" + "Emmanuel Holmes (747) 629-0925\n" + "Constantinople Café 364-67-KEBAB\n" + "Subtraction Consulting, Ltd 544-REMOVE-19\n" + "Nicole Haas 804.849.0601\n" + "Beverly Roberts 1.725.754.8597\n" + "Melba Patel 15504776792\n" + "Calgary Health and Safety Centre (403) CORONA-1\n" + "Hubert Sampson +1–(845)–674–6180\n" + "Supreme Seattle Flower Shop (425)-TULIPS-2\n" + "Verna Mayo 1 (815) 865-1650\n" + "Sherman Keller (678) 531-6758\n" + "Sharlene Dudley (829) 856-7001\n" + "Kate Guerra 540_6288287\n" + "Salvador Walters +1 830▸625▸3435\n" + "Kellie Freeman 1 (610) 464•578\n" + "Magdalena Glover +1(319)569-6421\n" + "Rachel Wang 530-848-0535\n" + "Boris Hoffman 868—686—9739\n" + "Vernon Philips 8794103965\n" + "Renee Frank 194033846507\n" + "Anthony McGrath (916) 629-6619\n" + "Brandon Monroe 1(854)591-5120\n" + "Zippers 123 321-ZIPPERS\n" + "Evangelina Strickland 1 (900) 675·1742\n" + "Vicente Bender 9375778873\n" + "Mattie Steele 1 (859) 878-6667\n" + "Antwan Blackwell (712) 866-8076\n" + "Chester York 918.7667576\n" + "Earl Vega 1–351–567–9758\n" + "Karin Gaines (514)▪265▪3029\n" + "Paul Holden 1 (475) 914-5650\n" + "Wallace Hughes 234-5853040\n" + "Christie Mitchell (934)-630-4558\n" + "Arnoldo Mclean 1-817-246-1456\n" + "Carroll Cuevas (934) 807 1799\n" + "Minnie Bradley (206)592.0746\n" + "Eva Lehman +1(249)971·9773\n" + "Gulf Coast Bridge Consultants 228-66-PYLON\n" + "Ralph's Hardware Emporium (409) WINGNUT\n" + "Charlene Houston 16047090550\n" + "Vicki Carey (500) 694_5031\n" + "Nicholas Singleton (679) 741-6462\n" + "Joseph Santos 8284942683\n" + "Stanford Terry +1(740)239-0940\n" + "Nichole Gibson (340) 981-3730\n" + "Elwood Newton (758) 621▪6349\n" + "Rory Rosario 1 (826) 785.2808\n" + "Dallas Museum of Space Exploration 21469ORBIT\n" + "24/7 Politics Podcast 535-OUTRAGE\n" + "Angelita Serrano 1-937-54-2057\n" + "Young Howe (325)562_7065\n" + "Riverside Consignment 951-CONSIGN\n" + "Joan Goodwin (548) 729-0155\n" + "Dave Bruce 709-539-8226\n" + "Sara Bernard (769) 207_7001\n" + "One Stop Magic Shop +1(434) 93-MAGIC\n" + "Jacob Newton (468)968▸1860\n" + "Island Diet Centre 345-71-CARBS\n" + "Swiss Culture Club 368.YODEL.44\n" + "Riley Harmon 253•325•3570\n" + "Cora Sawyer 912-410-4767\n" + "Marissa Sherman (847) 591–9982\n" + "Franklin Winter 646-527-7435\n" + "Kathie Martinez 585-886-3046\n" + "Claudia Blackburn (661) 375·2002\n" + "Jessie Mcgee 347·484·0577\n" + "Lemuel Carey 607801315\n" + "Gretchen Wu 5346955207\n" + "Louie Ho 1(526)880.0787\n" + "Brooke Massey 641•354•0826\n" + "Colleen McConnell 14739935288\n" + "Lonny Sandoval (925)984.2943\n" + "Joan Wong 1 (217) 239 6408\n" + "Celeste Wagner 682_479_1997\n" + "Maxine Reeves 1—847—200—7682\n" + "Janie Conley +1 (805) 820 2667\n" + "Nina Manning 518-936-5410\n" + "Cheerleading Warehouse 656 POMPOMS\n" + "Bennett Freeman (786)623.4656\n" + "Suffolk County Demolition Experts 631-BACKHOE\n" + "Kristie Tran 323-800-1567\n" + "Ye Olde Vintage Clothing Shoppe (528)-CRAVATS\n" + "Jeannie Lester 1—360—770—7631\n" + "Kerry Mckee +1—(570)—729—6561\n" + "Camille Burton (220).691.7942\n" + "Marilyn Greene (450)800-8228\n" + "Mckinley Mckenzie (615) 323-7248\n" + "Portland Medieval Armor Shop 971-53-JOUST\n" + "Kathy Bentley (538)297.0029\n" + "Truman Castaneda 1(281)956_9002\n" + "Chelsea Zamora (564) 599-1933\n" + "Garry Hoover 231•472•8212\n" + "Data Science, Inc (970)8 PANDAS\n" + "Amber Stout (938) 244–0140\n" + "Leonard Barnes 1 (708) 438 0412\n" + "Elmer Irwin 1 (781) 338—8712\n" + "April Moss (864) 605-7368\n" + "Fletcher Espinoza (251)696-5236\n" + "Stefanie Browning 1 606 878 1983b\n" + "Thurman Garza (825) 989▸4374\n" + "Paula Jones 1 (346) 388-2412\n" + "Amanda Franklin 518 562_9478\n" + "Cristopher Garrett 866 389-7213\n" + "Krystal Watson (826) 660.2221\n" + "Candice Leonard (807)782-2826\n" + "Morgan Anderson 1 (260) 696▸9101\n" + "Leo Wells 1-(947)-356-1568\n" + "Terrell Watts 4059925155\n" + "Josefina Crow 1-527-281-9621\n" + "Anna Groves +1—(649)—362—6399\n" + "Sergio Brewer 913.634.1346"; final String subst = "\\1\\n"; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); final Matcher matcher = pattern.matcher(string); // The substituted value will be contained in the result variable final String result = matcher.replaceAll(subst); System.out.println("Substitution result: " + result); } }

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