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

/
/

Test String

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 = "([A-z \\-]*)(?:,(( [A-z\\-\\.]*){0,3}(?:\\(I*\\))?))(.*)\\s(\\(.*\\))\\s*(\\[.*\\])?"; final String string = "Alba, Tota A la legi≤n le gustan las mujeres... y a las mujeres, les gusta la legi≤n (1976) [Do±a Euduviges] <20>\n" + "Alba, Vivi Parφs Tombuct· (1999) [Azafata]\n" + "Alba, Yashana Nightmare at Sleepaway Camp on Friday the 13th Part XII (2012) [Tammy Faye] <7>\n" + "Albacar, Mar \"└nima\" (2009) {(#6.3)} [Herself]\n" + "Albacete, Isabel Cßndida (2006) [Locutora Anuncio] <33>\n" + "Albach, Maeghan Evangerion shin gekij⌠ban: Jo (2007) (voice: English version) [Additional Voices]\n" + "Albach, Meaghan \"Suzuka\" (2005) {Egao (#1.2)} [Additional Voices]\n" + "Albach, Stephanie Handcart (2002) [Abigail] <2>\n" + "Albach-Retty, Rosa Abenteuer in Wien (1952)\n" + "Albachten, Kim As Virgins Fall (2003) [Madge Palsey]\n" + "Albadalejo, Ana L'Agent (2013) (V) [The Party] <6>\n" + "Albaicφn, Angustias Violetas imperiales (1952) (uncredited)\n" + "Albaicφn, Marφa El secreto del capitßn O'Hara (1968)\n" + "Albain, Julia A Very Potter Musical (2009) (TV) [Crabbe] <14>\n" + "Albajari, Nora La traque (2008) (TV) <40>\n" + "Albakry, Mouna Born of War (2014) [Wife] <17>\n" + "Albala, Shari Syx (2007) [Tour Group Member]\n" + "Albaladejo, Ana Cachorro (2004) [Profesora joven] <29>\n" + "Albaladejo, Geli 20 centφmetros (2005) [Funcionaria morena - Empleada ETT] <24>\n" + "Albaladejo, Lola Manolito Gafotas (1999) [Madre 1] <27>\n" + "Albaladejo, Maria \"└nima\" (2009) {(#7.17)} [Herself]\n" + "Albaladejo, Marina \"Menudo show\" (1995) {(1997-07-26)} [Paloma San Basilio]\n" + "Albaladejo, Rocφo \"La voz\" (2012) {(#1.1)} [Herself - Contestant]\n" + "Albaladejo, Tonia \"Teatro estudio\" (1976) {Las aleluyas del se±or Esteve}\n" + "Albalat, Laura Insaciable (2013) [Victima casa somni]\n" + "Albalate, Gloria Cinco minutos para medianoche (2010)\n" + "Albalate, N·ria Coco rallado (2008) [Mujer]\n" + "Albamonte, Cora Empalagßme que me gusta (2006) [Teodora]\n" + "Albamonti, Jennifer \"The Adventures of Indiana James\" (2015) [Bama Breeze Crew Member]\n" + "Alban, Alissa Carried Away (1996) [School Board Superintendent] <10>\n" + "Alban, Carolyn The Spectre of Edgar Allan Poe (1974) [Virginia Clemm] <17>\n" + "Alban, Chantal \"Janique aimΘe\" (1963) [IrΦne]\n" + "Alban, Elizabeth Wildflowers (1999) [Poker Player] <37>\n" + "Alban, Franτoise De quoi tu te mΩles Daniela! (1961) <6>\n" + "Alban, Ilse \"The Man Called X\" (1956) {Voice on Tape} <7>\n" + "Alban, Jamie The Halfway House (2004) (as Jaimie Alban) [Halfway House Girl] <25>\n" + "Alban, Jani Journal d'un coopΘrant (2010) [Mathilde]\n" + "Alban, Karine Dangerous Dreams - Die Macht des Geldes (2001) (V)\n" + "Alban, Luz Je suis barbara morgan (2015) [Danseuse]\n" + "Alban, Michele A±o u±a (2007) [Grandma Michele] <4>\n" + "Alban, Patricia Satanico Pandemonium: La Sexorcista (1975) <14>\n" + "Alban, Sarah Eden 11:11 (2010) [Young Girl, Cat]\n" + "Alban-Zapata, Joy Das geteilte Glⁿck (2010) (TV) [Mimi Wagner] <7>\n" + "Albana, Maya Danish Music Awards 2004 (2004) (TV) [Herself - Presenter (┼rets udenlandske hit)]\n" + "Albanchaabouchi, Kahina Bloody Mary (2011/I) [Air hostess]\n" + "Albane Rigadin et la poudre d'amour (1912)\n" + "Albane, Blanche L'homme au grand manteau (1911) <3>\n" + "Albanel, Christine L'aventure du Rond-Point: Audace joyeuse et rire de rΘsistance (2010) (TV) [Herself]\n" + "Albanense, Nadia \"Como pan caliente\" (1996) [Pelusa] <24>\n" + "Albanes, Carolina Agent: Undercover (2008) {{SUSPENDED}} [Luna]\n" + "Albanese, Anna \"Starcade\" (1982) {(#1.17)} [Herself - Contestant] <4>\n" + "Albanese, Ashleigh Crown Oaks Day (2011) (TV) [Herself]\n" + "Albanese, Chrissy Fat Kid Luv (2009) [Partygoer] <13>\n" + "Albanese, Francesca (R)evolution (2014) (V) [The Girl]\n" + "Albanese, Giada Banzai (1997) [Duty Free Cashier]\n" + "Albanese, Judy \"Cavuto on Business\" (2000) {(2014-07-18)} [Herself (segment \"Let Me Be Brief\")]\n" + "Albanese, Kelly Buffy the Vampire Slayer: Season 8 Motion Comic (2011) (V) [Buffy]\n" + "Albanese, Lauren \"Confessions of a Bartender\" (2015) [(2014)]\n" + "Albanese, Licia Little Shop of Erotica (2001) [Restaurant Patron] <21>\n" + "Albanese, Lindsay Operation Shock and Awe... some (2008) [Jenni]\n" + "Albanese, Marta Operaci≤n masacre (1973)\n" + "Albanese, Michela Il burbero (1986)\n" + "Albanese, Michele \"StartUpers\" (2012) [Herself] <3>\n" + "Albanese, Stephanie Eternal Black (2014) [Adult Sam/Narrator]\n" + "Albanese, Tina \"JAG\" (1995) {Code Blue (#2.13)} (uncredited) [Cashier]\n" + "Albanese, Zira Alzira's Story (2000) [Herself] <6>\n" + "Albanese-Smith, Amanda \"The Stools\" (2015) {Chapter Five: More 1957 (#1.5)} [Betheny Bedstuy-Jones]\n" + "Albanesi, Meggie Darby and Joan (1919) [Elin Garry] <5>\n" + "Albanez, Caroline Manny's Obituary (2011) [Maggie] <5>\n" + "Albanez, Diana \"Teachers Talking About...\" (2014) [Herself - Guest]\n" + "Albaneze, Ljiljana \"Svaki dan dobar dan\" (2013) {Ucenje - (Ni) je mucenje (#1.3)} [Herself]\n" + "Albanezzi, Nilza O Artesπo de Mulheres (1978) <10>\n" + "Albani, Andrea (I) Agφtese antes de usarla (1983) (as Laly Espinet) [Elisa] <11>\n" + "Albani, Angela Patima (1975) <20>\n" + "Albani, Elsa Come, quando, perchΘ (1969) [Marco's mother] <4>\n" + "Albani, Laura Auto-Ceva - Eine Begegnung und fⁿnf Reisen nach Bukarest (2010) [Herself] <2>\n" + "Albani, Marcella Amore in fuga (1921)\n" + "Albani, Maria Teresa Amore e ginnastica (1973) <11>\n" + "Albani, Olga The Lady in Black (1935) (as Countess Olga Albani) [Countess Olga Albani] <1>\n" + "Albani, Zoe Din prea multa dragoste (1986)\n" + "Albani-Cook, Maria \"Snapped: Killer Couples\" (2011) {Jennifer Henderson & Skylar Deleon (#1.2)} [Notary]\n" + "Albania, Annie In da Red Corner (2006) [Real Boxer] <66>\n" + "Albaniah, Nor Al-Hijab (2011) [Datin] <4>\n" + "Albano, Bea Edward Scissorhands (1990) [Rich Widow/TV] <36>\n" + "Albano, Donna A Modern Day Western: The Sanchez Saga (1997) [Detective Leslie Henderson]\n" + "Albano, Editha Thelma (2011) [Empanada Vendor, Batac Market] <28>\n" + "Albano, Flora R. My Name Is Bruce (2007) [Old Lady] <36>\n" + "Albano, Gia Santa Claws (2014) [Little Girl] <22>\n" + "Albano, Jennie (I) The Crib (2005) [Alluring Nurse #2]\n" + "Albano, Jennie (II) \"Take the Money & Run\" (2011) {The South Beach Sisters (#1.3)} [Herself - Contestant] <6>\n" + "Albano, Jennifer 200 Cigarettes (1999) [Cheryl] <3>\n" + "Albano, Jessica \"Prince$$\" (2010) {Laura H. (#2.27)} [Herself - Stylist]\n" + "Albano, Jill The Grounded (2013/I) [Missy-Ann] <1>\n" + "Albano, Kelly 30 Seconds from Oblivion (2010) (V) (as Kelly Marchand) [Lexi Warthers]\n" + "Albano, Mariela Placer sangriento (1967)\n" + "Albano, Martina La solitudine dei numeri primi (2010) [Young Alice] <3>\n" + "Albano, Mary La bestia desnuda (1971)\n" + "Albano, Meghan Pay It Forward (2000) (uncredited) [Neighbor]\n" + "Albano, Michele \"Throwdown with Bobby Flay\" (2006) {Pumpkin Pie (#7.5)} [Herself - Owner, Michele's Pies]\n" + "Albano, Patrizia Attenti a quei due napoletani (1980)\n" + "Albano, Pina Faida (1988)\n" + "Albano, Rebecca \"Take the Money & Run\" (2011) {The South Beach Sisters (#1.3)} (as Rebecca) [Herself - Contestant] <5>\n" + "Albano, Serena Ultime notizie (1995)\n" + "Albano, Stefania Il cappellino (2009)\n" + "Albano, Tulsi 10 Hours State of Emergency (2013) [News Reporter]\n" + "Albano, Victoria Jack Rio (2008) [Waitress]\n" + "Albanova, Olga Nelegal (2006) [Svetlana] <3>\n" + "Albany, Alison Busted (2015) [Office Worker] <19>\n" + "Albany, Fernande Flagrant dΘlit (1931) [Hortense] <7>\n" + "Albany, Jade (I) \"Camp\" (2013) {Pilot (#1.1)} [Alex] <18>\n" + "Albao, Baby Scaregivers (2008) [Jewelry Shop Customer] <57>\n" + "Albao, Theresita Scaregivers (2008) [Jewelry Shop Customer] <58>\n" + "Albar, Shelley The Bridge (2006/I) [Herself - David's Friend, Oakland, CA] <25>\n" + "Albarado, Clara La voz del agua (2015) [Mezzosoprano]\n" + "Albardonedo, Deborah Bellas durmientes (2001) [Mujer de cuatro piernas] <29>\n" + "Albareda, Teresa Pell Fina (2015)\n" + "Albareil, Josette PygomΦle (2011) [La Servante] <5>\n" + "Albarella, Jackie Traveling Salesmen (2008) [Mystic Judy Giordano] <6>\n" + "Albarella, Karen Fixations (2010) [Group Member]\n" + "Albarelli, Kathryn \"Law & Order: Criminal Intent\" (2001) {Unchained (#5.4)} [Judy Cordova] <26>\n" + "Albares, Ana Isabel (I) XIV Premios Anuales Iris de la Academia de TV (2012) (TV) [Herself]\n" + "Albares, Ana Isabel (II) XIV Premios Anuales Iris de la Academia de TV (2012) (TV) [Herself - Presenter]\n" + "Albaret, Sylvia Les chants de Mandrin (2011) [Mandrinette] <10>\n" + "Albarez, Angela Franchise (2012)\n" + "Albarez, Maria Dolores Ellos Volvieron (2015) [Classmate] <21>\n" + "Albaroto, Carla Thelma (2011) [University of Makati] <491>\n" + "Albarracin, Mayra Insane (????) [Belen]\n" + "Albarracin, Taca Nocturnal Jake (2009) [Sophia] <2>\n" + "Albarracφn, Adriana \"La casa de las dos palmas\" (1991) [Hortencia Herreros (1991)]\n" + "Albarracφn, Magnolia La pasi≤n de Gabriel (2008) [Do±a Carmen]\n" + "Albarracφn, Marcela Invierno ausente (2005) [Elvira]\n" + "Albarracφn, Nadia \"Guapas\" (2014) {Falsa alarma (#1.168)} [Bombero]\n" + "Albarreal, Cecilia Dramagogφa barata (2005)\n" + "Albarret, CΘleste Portrait-souvenir: Marcel Proust (1962) (TV) [Herself]\n" + "Albarrosa, Rosanny Stand Clear of the Closing Doors (2013) [Nail clipper]\n" + "Albarrßn, Karla \"Amor gitano\" (1999) <32>\n" + "Albarrßn, Socorro 2 sinaloenses y 3 colombianas (1998) [Cela]\n" + "Albarus-Lindo, Carmeta \"Aftermath with William Shatner\" (2010) {Confessions of the DC Sniper with William Shatner: An Aftermath Special (#1.0)} [Herself] <7>\n" + "Albas, Michelle \"Crash Test Mommy\" (2004) {Michelle Albas (#1.8)} [Herself - Crash Test Mommy]\n" + "Albas, Montse Omar Martφnez (2006) (TV) [MΘdico] <15>\n" + "Albasetti, Eliana \"Buenos dφas a todos\" (1991) {(2013-07-08)} [Herself - Guest]\n" + "Albassam, Dalia Gone (2004/II) [Daughter]\n" + "Albassam, Sahar Gone (2004/II) [Mom]\n" + "Albat, Elvan Seytan-i Racim 2: Ifrit (2015)\n" + "Albat, Taiye Aje metta (2008) (V) [Ara ile] <11>\n" + "Albates, Eva \"Streit um Drei\" (1998) {(#1.284)} [Gisela Bubner]\n" + "Albatis, Marie Herzlutschen (2004) [Swetlana Erdmann]\n" + "Albats, Evgeniya Srok (2014) (uncredited) [Herself]\n" + "Albaugh, Bridget Fly on the Wall (2016) [Gwen]\n" + "Albaugh, Cheryl The Spirits: A Christmas Story (2013) [Extra]\n" + "Albaugh, Sally Desperate Living (1977) [Hag] <24>\n" + "Albaum, Haley Swimming to the Moon (2007) [Background]\n" + "Albaum, Morgan Swimming to the Moon (2007) [Waitress/Dancer]\n" + "Albayati, Anwar Ett ÷ga r÷tt (2007) [Dalanda]\n" + "Albayaty, Leila Berlin Telegram (2012) [Leila]\n" + "Albayaty, Simone Ka∩ros (2015) [Herself]\n" + "Albayrak, Fulya \"Melek\" (2002) [(2002)]\n" + "Albayrak, Maria \"Idol\" (2004) {(#2.1)} [Herself]\n" + "Albayrak, Nahsen Sahinler diyari (1958)\n" + "Albayrak, Nebahat \"Barend en Van Dorp\" (1990) {(2001-11-30)} [Herself - Kamerlid PvdA] <4>\n" + "Albayrak, Nurten \"Pauw & Witteman\" (2006) {(#6.74)} [Herself - Directeur COA] <6>\n" + "Albayrak, Tugce \"CNN Newsroom\" (1989) {(2014-11-27)} (archive footage) [Herself - Prⁿgelopfer]\n" + "Albaz, Sana Broken Wings (????) [Herself]\n" + "Albe, Celeste A sangre frφa (las reglas del juego) (2007) [Periodista] <6>\n" + "Albe, Dawn The Least of These (1995) (TV) [Roxanne] <5>\n" + "Albe, Marie Cause toujours, mon lapin (1961)\n" + "Albea, Ami Zombie Apocalypse (2011) (TV) [Zombie] <12>\n" + "Albech, Lillian I lossens time (2013) [Indsat 4]\n" + "Albeck, Alysia The Love Doctor (2015) [Fan]\n" + "Albeck, Bruria Kafe V'Limon (1994) [Michal] <3>\n" + "Albeck, Christine Halby \"Klovn\" (2005) {Ups (#4.10)} [Christine]\n" + "Albeck, Else Det sande ansigt (1951) <12>\n" + "Albeck, Jeanett \"Jarls quizshow\" (2012) {(#1.1)} [Herself - Conductor]\n" + "Albeck, Lillan Fasandrµberne (2014) [Posedame pσ hovedbanegσrden] <44>\n" + "Albeck, Lillian \"Karrusel\" (1998) {8/Ulrich og Lotte (#1.8)} (uncredited) [Dame ved billetlugen]\n" + "Albeck, Lis Flagermusen (1966) <40>\n" + "Albecker, Anne-Claire La chance de ma vie (2011) [RΘceptionnniste h⌠tel] <29>\n" + "Albeda, Martha Mind Walls (2011) [Prakruti]\n" + "Albediwa, Neeven Dark Places (2005) [Donna] <13>\n" + "Albee Sisters, The Turn Off the Moon (1937) [The Albee Sisters] <13>\n" + "Albee, Becca The Punk Singer (2013) [Herself] <6>\n" + "Albee, Gloria Still Dreaming (2014) [Herself - Helena]\n" + "Albee, Lori Naked Ambition: An R Rated Look at an X Rated Industry (2009) (as JC's Girls) [Herself - Christian Outreach Ministry] <8>\n" + "Albee, Lura \"Mike Hammer\" (1984) {Sex Trap (#1.7)} [Elegant Lady]\n" + "Albee, Mary Crisis in Mid-air (1979) (TV) <45>\n" + "Albee, Nicole (II) The Education Channel (2012) (V) [Herself]\n" + "Albee, Pat Syx (2007) [SYX recruit]\n" + "Albee, Payton What Lies Within Us (2015) [Phoebe]\n" + "Albee, Roxanne (I) Hot Rods to Hell (1967) (uncredited) [Dancer in Floral Outfit]\n" + "Albee, Roxanne (II) Young Guns (2013) [Diana]\n" + "Albeen, Allison Camera Shy (2004) [The Girl] <2>\n" + "Albelda, Mitch Ang huling henya (2013) [Extras at Club Ramp] <150>\n" + "Albelda, Nuria Redes de traici≤n (2014) [Chica exterior]\n" + "Albelo, Anna Margarita Hooters! (2010) [The Investigator]\n" + "Alben, Adriana Aquile (1990) (TV) [Madre di Ferrara]\n" + "Alben, Emily The Feline Feeling (2014) [Hazel Bulleit]\n" + "Albeneau, Cristina L'elefante Rosa (2004)\n" + "Albenga, Cristina La sagrada familia (1988) <15>\n" + "Albeniz, Cecilia La traversΘe du dΘsir (2009) [Herself]\n" + "Alber, Alix Aase AyoΘ Et Syndens Barn (1913) [The Child]\n" + "Alber, Aloma D. Take-Away Spirit (2009)\n" + "Alber, Ariane Glⁿckliche Tage - Am Rande des Abgrunds (1995) [Herzegowina Bihaτ]\n" + "Alber, Franziska Das Haus Anubis - Pfad der 7 Sⁿnden (2012) [Delia] <4>\n" + "Alber, Kim Goblin (1993) (V) [Sherry] <5>\n" + "Alber, Marjorie-Sue \"Ripley's Believe It or Not!\" (1999) {(#1.20)} [Herself - Roger's Daughter]\n" + "Albera, Blanche IrΦne Leτon de vie (1995)"; final Pattern pattern = Pattern.compile(regex); final Matcher matcher = pattern.matcher(string); if (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i <= matcher.groupCount(); i++) { System.out.println("Group " + i + ": " + matcher.group(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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html