Regular Expressions 101

Save & Manage Regex

  • Current Version: 9
  • 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

$re = '/^(?<title>.+?)[_.\s-]+(?<season>S\d+)(?:[.\-\s]*?(?<seasonmax>S?\d+))?(?=[_.\s](?!E\d+))/mi'; $str = 'Cops.S35E18.1080p.WEB.h264-BAE.mkv Anger Management (2012) - S02E15 - Charlies Patients Hook Up [WEBDL-1080p][AC3 5.1][h264]-BS.mkv Ahsoka (2023) - S01E01 - Part One Master and Apprentice [DSNP WEBDL-1080p][EAC3 Atmos 5.1][h264]-NTb.mkv\' Loki....... - S01E01 - Glorious Purpose [DSNP WEBDL-1080p Proper][EAC3 Atmos 5.1][h264]-TOMMY.mkv\' Family - Guy (1999) - S01E01 - Death Has a Shadow [DSNP WEBDL-1080p][AAC 2.0][h264]-PHOENiX.mkv\' Neighbours.S39E012.2023-10-05.Episode.8915.1080p.AMZN.WEB-DL.DDP2.0.H.264-SDCC Rick and Morty (2013) - S06E06 - JuRicksic Mort [HMAX DD 5.1 WEBDL-1080p][x264]-NTb.mkv Hello.World.S01.ntb.mkv Hello.World.S01 - S03.ntb.mkv Hello.World.S1.ntb.mkv Hello.World.S01 S03.ntb.mkv Hello.World.S01.Extras.ntb.mkv Hello_World_S01_S02.ntb.mkv Hello_World_S01-S03_ntb.mkv Hello_World_S1_ntb.mkv Hello.World.S1E03.ntb.mkv Hello.World.S031 E01.ntb.mkv Hello_World_S01E01_ntb.mkv Hello_World_S1E03_ntb.mkv Hello.World.S01.E01.ntb.mkv Hello_World_S01_E01_ntb.mkv'; 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