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

/
/
g

Test String

Code Generator

Generated Code

$re = '/([0-9]{1,}:[0-9]{1,})/'; $str = '...New developments in the ongoing controversy 0:05 surrounding Molecular Genetics. 0:07 Incoming reports now allege 0:08 MolGen’s involvement in illegal human cloning. 0:11 In a startling development, it appears 0:12 private security forces have taken over. 0:15 All this just two weeks after the controversial disappearance 0:18 of MolGen Chief Medical Officer Dr. Nora Phillips. 0:22 Anonymous sources saying there could be actual human clones inside. 0:44 Up and at ‘em, Five. 0:45 Let’s go. Get up! 0:49 Sir, FBI just breached the lobby. 0:51 It’s getting down to the wire. 0:53 Guess we better hurry then. 0:55 Get up, Five! 0:58 Why do you always have to make everything so hard. 1:01 Let\'s go. 1:05 Chrissakes, is that really necessary? 1:08 Keep moving. Keep moving. 1:14 All clear, let\'s go. 1:22 Let’s go! Move, move, move! 1:24 Goddamn abomination. 1:32 In position. Driver’s coming in. 1:39 Abomination. 1:41 Get the door, please. 1:47 Abomination. 1:49 From the latin word "abominari". 1:52 A thing that causes hatred or disgust. 1:54 Gentlemen, the specimen stays with me at all times. 1:58 Lead, follow, you offer support. 1:59 There is also an air unit that is active. 2:02 Right now we are surrounded by the FBI. 2:05 We will move out. We will move fast. 2:07 And if necessary we will push back. 2:10 The only thing that matters now 2:12 is getting the merchandise to the customer. 2:18 Let’s see if you’re worth the money. 2:20 You don’t need to baby-sit me. 2:22 I baby-sit everyone. 2:24 That’s kinda my thing. 2:38 What the — 3:04 They’re moving in. You got six on your tail. 3:06 Xavier, do me a favor. 3:07 Push ‘em back a little bit. 3:24 This is your world? 3:27 Have you never seen it before? 3:28 Drive the car. 3:29 Not with my eyes, no. 3:30 Five. Shut up. 3:32 But I know all about your world. 3:33 Really? 3:34 Do not communicate with the specimen... 3:37 - Alaska has a longer coastline... - Five... 3:39 - ...than all other 49 states combined. - Stop talking. 3:40 - If you want, I could tell you some — - Five, stop talking! 3:44 My name is Lilly. 3:47 Okay. 3:50 Please, those are mine. 3:51 I love her work. It’s great, isn’t it. 3:54 Such detail. That’s my favorite. 3:57 She\'s really something else. 4:17 Okay... 4:19 Cut him off! 4:21 Stop the car. 4:26 Three seconds. 4:28 Two. 4:30 One. 4:35 Get out. 4:37 Okay. 4:38 Do you have any idea what you just did? 4:48 I might be a little rusty right now, 4:50 but I’ve been doing this for a long time. 4:52 I’m very good at it. 4:53 That only means your chances 4:54 of failure increase with each outing. 4:57 Statistically speaking. 4:59 The odds will be what the odds will be. 5:01 Get out. 5:03 You’re dead, mystery man. 5:05 You’re dead. 5:08 You mind? 5:18 Air unit one in pursuit. 5:20 No, no, no, no, the driver’s mine! 5:22 Buckle up... 5:36 Let’s go, let’s go! 5:47 Lower! Lower! 5:53 Lower! 5:54 What part of “lower” don’t you understand?! 7:58 Mercy. 7:59 From Old French, merced. 8:02 Kindness. Grace. Pity. 8:30 Put your hands up! 8:31 On your knees! 9:00 You okay? 9:05 Dr. Phillips. 9:08 Yes. 9:10 She made Tulip and Rose and Daffodil... 9:14 and me. 9:17 They’re all gone now. 9:22 Look. 9:39 Hello, Lilly. 9:56 Keep it. 9:57 Thank you. '; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); // Print the entire match result var_dump($matches);

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 PHP, please visit: http://php.net/manual/en/ref.pcre.php