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

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

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 JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions