Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • 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

/
/
gm

Test String

Code Generator

Generated Code

$re = '/<text[^>]+>([^<]+)<\/text>/m'; $str = 'This XML file does not appear to have any style information associated with it. The document tree is shown below. <transcript> <text start="9.462" dur="1.123">Aaaah</text> <text start="10.585" dur="1.646">It&#39;s Rewind time.</text> <text start="12.341" dur="3.721">If I controlled Rewind I would want</text> <text start="16.062" dur="3.161">Fortnite and Marques Brownlee.</text> <text start="24.834" dur="1.014">Is this what you wanted?</text> <text start="25.848" dur="1.887">You know who I would have asked for?</text> <text start="27.944" dur="1.557">Quit horsing around.</text> <text start="30.239" dur="2.217">Play me some of that jumping music.</text> <text start="32.676" dur="1.336">Did you say jumping music?</text> <text start="34.072" dur="1.266">Jumping music?</text> <text start="39.622" dur="1.28">Everybody! Off!</text> <text start="48.192" dur="1.847">Not even a thank you?!</text> <text start="57.676" dur="1.762">Is that Marques?</text> <text start="59.438" dur="1.597">I want Liza!</text> <text start="64.405" dur="3.644">Yeaaaaaahhhh!!!!</text> <text start="70.507" dur="5.51">So guys, apparently we control Rewind this year.</text> <text start="76.017" dur="4.842"> Y&#39;all we can do whatever we want. What do we do? </text> <text start="85.011" dur="3.299">There&#39;s one thing this video needs.</text> <text start="88.31" dur="1.989">K-pop!</text> <text start="108.973" dur="2.159">Can I have a Royal Wedding?</text> <text start="111.132" dur="1.73">Yeah, but you&#39;re marrying Bongo Cat.</text> <text start="112.863" dur="1">Wait, what?</text> <text start="122.334" dur="1.587">Rewind needs more science.</text> <text start="123.921" dur="1.473">Can we do an experiment?</text> <text start="125.758" dur="2.359">I love that. Melting lipstick.</text> <text start="133.23" dur="1.332">I want to eat something.</text> <text start="135.102" dur="1.743">Mukbang!</text> <text start="136.845" dur="1.98">Yes, let&#39;s do it in Korea!</text> <text start="145.191" dur="1.307">Gallop, what do you want?</text> <text start="154.964" dur="2.042">Marshmello needs to be in this video.</text> <text start="158.036" dur="1.298">Who is Marshmello?</text> <text start="159.675" dur="1.835">How about yodeling kid?</text> <text start="162.104" dur="1.29">With Adam Rippon!</text> <text start="182.612" dur="2.332">Guys, let&#39;s do the In My Feelings challenge.</text> <text start="184.944" dur="1.014">Right!</text> <text start="188.239" dur="1.193">I love this song!</text> <text start="189.432" dur="1.68">Let&#39;s hear the remix!</text> <text start="222.998" dur="2.064">Wait, wait, wait. Hold on, hold on.</text> <text start="225.062" dur="3.274"> You know who really needs to be in this Rewind video? </text> <text start="228.336" dur="3.062"> Everyone who managed to do something bigger than themselves this year. </text> <text start="231.398" dur="3.266"> Found a way to help the causes that matter to them most. </text> <text start="234.664" dur="3.423"> To everyone who proved it&#39;s ok to talk about mental health this year. </text> <text start="238.087" dur="3.443"> Showing our viewers that it&#39;s ok to go through tough times like that. </text> <text start="241.53" dur="4.122"> It takes a lot of bravery to be that vulnerable and I&#39;m so proud of this community. </text> <text start="245.652" dur="4.046"> I think this year&#39;s Rewind should celebrate the fierce, fabulous </text> <text start="249.698" dur="1.893">and empowering art of drag.</text> <text start="251.591" dur="3.027"> I want to see all of you be your own kind of beautiful. </text> <text start="254.618" dur="3.121"> And to those people who have raised money in the field of education. </text> <text start="257.739" dur="4.628"> Can we also give a moment to Asian representation in entertainment this year? </text> <text start="262.367" dur="1.393">Major strides were made.</text> <text start="263.76" dur="2.018"> And to the people who put aside their differences. </text> <text start="265.778" dur="1.837">Yeah, and created something really special.</text> <text start="267.615" dur="3.769"> Here&#39;s to all women in 2018 for finding their voices. </text> <text start="271.384" dur="3.614"> It&#39;s nice seeing how women grew and were empowered. </text> <text start="274.998" dur="2.778"> Can we give a moment to working moms? Let&#39;s do it! </text> <text start="277.776" dur="4.5"> To everyone who taught, or learned, something new this year. </text> <text start="282.276" dur="3.061"> And to all the refugees and anyone looking for a home. </text> <text start="285.337" dur="4.201"> All of us should send a toast to the kids who follow their dreams. </text> <text start="289.538" dur="4.888"> I want to thank the whole community that always supports during our best and worst. </text> <text start="294.426" dur="2.262">We are a family, we are a team.</text> <text start="296.688" dur="1.772">Family is everything.</text> <text start="298.46" dur="3.764"> I want to give a moment to everyone who supported me when I got sick. </text> <text start="302.224" dur="4.087"> All of the comments and messages I got made me feel like I wasn&#39;t alone. </text> <text start="307.222" dur="2.177">We&#39;re forgetting something.</text> <text start="311.312" dur="3.11">I think we should read the comments.</text> <text start="322.401" dur="4.34"> Yeah I have a feeling this is going to get a little bit crazy. </text> <text start="326.741" dur="2.77">Let&#39;s give the people what they want.</text> <text start="413.038" dur="1.51">Aaaahhh</text> <text start="417.803" dur="2.29">That&#39;s hot, that&#39;s hot.</text> </transcript>'; 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