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

$re = '/<td class="result_text"> <a href="\/title\/tt([0-9]+)\/\?ref_=[a-zA-Z0-9_]+" >((?:(?!<\/a>).)*?)<\/a>/'; $str = ' <tr class="findResult odd"> <td class="primary_photo"> <a href="/title/tt4158110/?ref_=fn_al_tt_1" ><img src="http://ia.media-imdb.com/images/M/MV5BMTg3OTQ2NzAzN15BMl5BanBnXkFtZTgwMDUyNjY3NTE@._V1_UX32_CR0,0,32,44_AL_.jpg" /></a> </td> <td class="result_text"> <a href="/title/tt4158110/?ref_=fn_al_tt_1" >Mr. Robot</a> (2015) (TV Series) </td> </tr><tr class="findResult even"> <td class="primary_photo"> <a href="/title/tt4730026/?ref_=fn_al_tt_2" ><img src="http://ia.media-imdb.com/images/M/MV5BMjIzOTE2MjIwMl5BMl5BanBnXkFtZTgwMzQ1ODU0NjE@._V1_UY44_CR17,0,32,44_AL_.jpg" /></a> </td> <td class="result_text"> <a href="/title/tt4730026/?ref_=fn_al_tt_2" >eps1.7_wh1ter0se.m4v</a> (2015) (TV Episode) <br/><small>- <a href="/title/tt4158110/?ref_=fn_al_tt_2a" >Mr. Robot</a> (2015) (TV Series) </small> </td> </tr><tr class="findResult odd"> <td class="primary_photo"> <a href="/title/tt4730002/?ref_=fn_al_tt_3" ><img src="http://ia.media-imdb.com/images/M/MV5BNDMyODE0MDcyOV5BMl5BanBnXkFtZTgwMDA4MzgxNjE@._V1_UY44_CR17,0,32,44_AL_.jpg" /></a> </td> <td class="result_text"> <a href="/title/tt4730002/?ref_=fn_al_tt_3" >eps1.2_d3bug.mkv</a> (2015) (TV Episode) <br/><small>- <a href="/title/tt4158110/?ref_=fn_al_tt_3a" >Mr. Robot</a> (2015) (TV Series) </small> </td> </tr><tr class="findResult even"> <td class="primary_photo"> <a href="/title/tt4652838/?ref_=fn_al_tt_4" ><img src="http://ia.media-imdb.com/images/M/MV5BMTY4MDgwMzEwMl5BMl5BanBnXkFtZTgwMzgzMzk5NTE@._V1_UY44_CR17,0,32,44_AL_.jpg" /></a> </td> <td class="result_text"> <a href="/title/tt4652838/?ref_=fn_al_tt_4" >eps1.0_hellofriend.mov</a> (2015) (TV Episode) <br/><small>- <a href="/title/tt4158110/?ref_=fn_al_tt_4a" >Mr. Robot</a> (2015) (TV Series) </small> </td> </tr><tr class="findResult odd"> <td class="primary_photo"> <a href="/title/tt4799588/?ref_=fn_al_tt_5" ><img src="http://ia.media-imdb.com/images/M/MV5BNjAyNzM1NzkzOV5BMl5BanBnXkFtZTgwOTI3MDk1NjE@._V1_UY44_CR17,0,32,44_AL_.jpg" /></a> </td> <td class="result_text"> <a href="/title/tt4799588/?ref_=fn_al_tt_5" >eps1.8_m1rr0r1ng.qt</a> (2015) (TV Episode) <br/><small>- <a href="/title/tt4158110/?ref_=fn_al_tt_5a" >Mr. Robot</a> (2015) (TV Series) </small> </td> </tr><tr class="findResult even"> <td class="primary_photo"> <a href="/title/tt4730012/?ref_=fn_al_tt_6" ><img src="http://ia.media-imdb.com/images/M/MV5BMzQ5NTg5ODQyMV5BMl5BanBnXkFtZTgwNjcxNzMzNjE@._V1_UY44_CR17,0,32,44_AL_.jpg" /></a> </td> <td class="result_text"> <a href="/title/tt4730012/?ref_=fn_al_tt_6" >eps1.4_3xpl0its.wmv</a> (2015) (TV Episode) <br/><small>- <a href="/title/tt4158110/?ref_=fn_al_tt_6a" >Mr. Robot</a> (2015) (TV Series) </small> </td> </tr><tr class="findResult odd"> <td class="primary_photo"> <a href="/title/tt4659980/?ref_=fn_al_tt_7" ><img src="http://ia.media-imdb.com/images/M/MV5BMjA1MjYxNzczM15BMl5BanBnXkFtZTgwMjU4MzgxNjE@._V1_UY44_CR17,0,32,44_AL_.jpg" /></a> </td> <td class="result_text"> <a href="/title/tt4659980/?ref_=fn_al_tt_7" >eps1.3_da3m0ns.mp4</a> (2015) (TV Episode) <br/><small>- <a href="/title/tt4158110/?ref_=fn_al_tt_7a" >Mr. Robot</a> (2015) (TV Series) </small> </td> </tr><tr class="findResult even"> <td class="primary_photo"> <a href="/title/tt4686038/?ref_=fn_al_tt_8" ><img src="http://ia.media-imdb.com/images/M/MV5BMTg0NTkwMTc1NF5BMl5BanBnXkFtZTgwNzY3MzgxNjE@._V1_UY44_CR17,0,32,44_AL_.jpg" /></a> </td> <td class="result_text"> <a href="/title/tt4686038/?ref_=fn_al_tt_8" >eps1.1_ones-and-zer0es.mpeg</a> (2015) (TV Episode) <br/><small>- <a href="/title/tt4158110/?ref_=fn_al_tt_8a" >Mr. Robot</a> (2015) (TV Series) </small> </td> </tr><tr class="findResult odd"> <td class="primary_photo"> <a href="/title/tt4730014/?ref_=fn_al_tt_9" ><img src="http://ia.media-imdb.com/images/M/MV5BMTc2NDc0ODc3MV5BMl5BanBnXkFtZTgwODYxNzMzNjE@._V1_UY44_CR17,0,32,44_AL_.jpg" /></a> </td> <td class="result_text"> <a href="/title/tt4730014/?ref_=fn_al_tt_9" >eps1.5_br4ve-trave1er.asf</a> (2015) (TV Episode) <br/><small>- <a href="/title/tt4158110/?ref_=fn_al_tt_9a" >Mr. Robot</a> (2015) (TV Series) </small> </td> </tr><tr class="findResult even"> <td class="primary_photo"> <a href="/title/tt4652854/?ref_=fn_al_tt_10" ><img src="http://ia.media-imdb.com/images/M/MV5BMzUyMzIxMDY2N15BMl5BanBnXkFtZTgwNTU3MDk1NjE@._V1_UY44_CR17,0,32,44_AL_.jpg" /></a> </td> <td class="result_text"> <a href="/title/tt4652854/?ref_=fn_al_tt_10" >eps1.9_zer0-day.avi</a> (2015) (TV Episode) <br/><small>- <a href="/title/tt4158110/?ref_=fn_al_tt_10a" >Mr. Robot</a> (2015) (TV Series) </small> </td> </tr></table> <div class="findMoreMatches">'; preg_match($re, $str, $matches, PREG_OFFSET_CAPTURE, 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