Regular Expressions 101

Save & Manage Regex

  • Current Version: 5
  • Save & Share
  • Community Library

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
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 java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "\\b((?:INT|EXT)\\..*\\S)[^\\S\\n]+[a-zA-Z]*\\d+\\n(?s:(.+?)(?=\\b(?:EXT|INT)\\.|\\Z))"; final String string = "7 INT. COLONY HOTEL - STAIRWELL - NIGHT 7\n" + " Lowrey and Burnett clip on their shields and unholster\n" + " their guns. The posing is over. This is business.\n\n\n" + "A8 INT. COLONY HOTEL - SUITE 202 - NIGHT A8\n" + " On the table are two briefcases. Each opened. One\n" + " containing cocaine. The other, cash. A pistol next\n" + " to each.\n\n" + "26 EXT. POLICE STATION ALLEY - NIGHT 26\n" + " Bag after bag drops down the trash chute and tumbles into\n" + " an open-roofed van where the last of the gang, Eddie\n" + " Dominguez, waits with the ENGINE RUNNING.\n\n\n" + "27 IN AIR DUCT 27\n" + " The sled rockets by again -- WHOOSH -- loaded with more\n" + " bags.\n\n\n" + "28 INT. HEROIN LOCKER 28\n" + " Casper and Fouchet throw the last of their gear down the\n" + " chute and ride the sled out.\n\n\n" + "29 EXT./INT. VAN - POLICE STATION - ALLEY 29\n" + " One! Two! Three! Four! They all land atop the bags.\n" + " Eddie GUNS the VAN, which rolls up the ramp and out the\n" + " garage.\n" + " (CONTINUED)\n\n\n" + " 8.\n" + "29 CONTINUED: 29\n" + " FOUCHET (O.S.)\n" + " Haul ass!\n\n\n" + "30 EXT. POLICE STATION - ALLEY - NIGHT 30\n" + " On the ledge the tape runs out and RECORDER EXPLODES.\n" + " Pieces scatter.\n\n\n" + "31 EXT. STREET - NIGHT 31\n" + " The van drives off into the golden sunrise of Miami.\n" + " TITLES END.\n\n\n" + "32 EXT. LUXURY HIGH-RISE (COCONUT GROVE) - MORNING 32\n" + " One of those expensive condo buildings on Brickell Avenue\n" + " with a circular driveway and a uniformed doorman.\n\n\n" + "33 INT. CONDO - MORNING 33\n" + " CAMERA TRACKS THROUGH expensive and trendy bachelor's\n" + " lair. State-of-the-art everything, gorgeous artwork.\n" + " Spectacular view.\n" + " CAMERA STALLS ON -- a perma-plaqued newspaper clipping\n" + " with a photo depiction of Lowrey and Burnett in front of\n" + " a giant pile of black heroin, thumbs up to the camera.\n" + " The headline reads: MIAMI PD RECORDS RECORD HEROIN BUST.\n\n\n" + "34 INT. LOWREY'S BEDROOM - MORNING 34\n\n\n" + " Where Lowrey wakes up in a king-sized bed. The pain on\n" + " his face and empty, scattered bottles tell us he's\n" + " nursing a world-class hangover. He sits up, carefully,\n" + " holds his aching head. Hearing BREATHING, Lowrey lifts\n" + " the sheet next to him.\n\n\n" + " REVEAL THE LATINA\n" + " The one from the Colony Hotel. He drops the sheet back\n" + " over her head, reaches over to his nightstand and grabs\n" + " an industrial-sized bottle of Excedrin. Empty. He opens\n" + " the nightstand drawer, extracts another bottle. Empty.\n\n\n" + " BAD BOYS - Rev. 6/22/94 9.\n" + "35 INT. BATHROOM 35\n" + " All marble and brass. Lowrey opens up his medicine\n" + " cabinet. Locating a new bottle of aspirin... he suddenly\n" + " realizes that the SHOWER is RUNNING. Confused, he pulls\n" + " open the shower curtain slightly. From the back, it's an\n" + " incredible body, then she turns around and it's --\n" + " THE LATINA\n" + " Yes. The very same as the one he just saw in bed. What?\n" + " LATINA TWIN\n" + " 'Morning.\n" + " Lowrey closes the curtain on her. Frowns at this\n" + " impossibility. He steps back into the doorway and peers\n" + " over at his bed. Yep, same face. Twins?\n" + " LOWREY\n" + " (shaking his head)\n" + " Oh man...\n" + " He tears open the bottle of aspirin. Chug-a-lugs.\n\n\n" + "36 INT. BURNETT HOUSE - BEDROOM - MORNING 36\n" + " Burnett and his young wife, THERESA, are jarred awake by\n" + " the CLOCK RADIO BLARING on the night stand. Theresa\n" + " gropes for RADIO, shuts it OFF. Burnett playfully gropes\n" + " for her.\n" + " THERESA\n" + " Marcus, what are you doing?\n" + " BURNETT\n" + " We're always saying we should\n" + " spend more quality time together.\n" + " Well, I got the time... and you\n" + " got the quality...\n" + " She laughs. He kisses her.\n" + " BURNETT\n" + " I can remember when we used to\n" + " do it every morning.\n" + " THERESA\n" + " That was how we got a three\n" + " bedroom house filled with little\n" + " Burnetts.\n" + " She crawls from bed.\n" + " BURNETT\n" + " Been over a week since I've had\n" + " some quality time!\n\n\n" + " BAD BOYS - Rev. 6/22/94 10.\n" + "37 INT. BURNETT'S KITCHEN - MORNING 37\n" + " Pandemonium. There's the two-and-a-half-year-old,\n" + " MEGAN, who's taking bites of food and spitting it back\n" + " out, looking at it, then putting it back in. Six-year-\n" + " old JILL, who is playing refrigerator magnet games on the\n" + " fridge. And Marcus in the middle of it all, deftly side-\n" + " stepping his eight-year-old boy, QUINCY, who appears on\n" + " roller blades whizzing through with a hockey stick and\n" + " ball. He body-checks Jill against the ice box.\n" + " JILL\n" + " Mom, Quincy pushed me.\n" + " QUINCY\n" + " Uncle Mike showed me that move.\n\n\n" + " THERESA\n" + " Quincy, never-you-mind. And take\n" + " those things off in the house!\n" + " Jill, stop with the book and eat\n" + " your breakfast.\n" + " (then, exasperated)\n" + " Marcus, why do I always have to\n" + " discipline the kids? You play\n" + " bad cop for a second.\n" + " Alongside the kitchen screen door we see Lowrey's PORSCHE\n" + " ROAR to a stop in the driveway.\n" + " BURNETT\n" + " Kids, knock it off... or your\n" + " momma's gonna whoop your butts!\n" + " Theresa laughs in spite of herself as the kids continue\n" + " to fight. Into this craziness enters Mike Lowrey...\n" + " LOWREY\n" + " Ah, family life. Reminds me\n" + " why I stay single.\n" + " JILL & QUINCY\n" + " Uncle Mike! Uncle Mike!\n" + " LOWREY\n" + " Hiya, kids. Mornin', Theresa.\n" + " Lowrey pecks Theresa on the cheek. She recoils.\n" + " THERESA\n" + " Don't kiss me, Lowrey. I don't\n" + " know where those lips were last\n" + " night.\n" + " (CONTINUED)\n" + " "; final Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE); final Matcher matcher = pattern.matcher(string); while (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