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 = '/\"year\"\:(\d{4})\,/'; $str = '{"total_pages":1,"total_count":3,"per_page":60,"page":1,"data":[{"id":"524414","type":"subtitle","attributes":{"subtitle_id":"524414","language":"ro","download_count":1421,"new_download_count":1,"hearing_impaired":false,"hd":false,"fps":25.0,"votes":0,"ratings":0.0,"from_trusted":false,"foreign_parts_only":false,"upload_date":"2010-03-07T08:17:40Z","ai_translated":false,"machine_translated":false,"release":"Casino Royale - oo7","comments":"AUTOLOAD AUTOUPLOAD","legacy_subtitle_id":3650579,"uploader":{"uploader_id":3282,"name":"os-auto","rank":"Application Developers"},"feature_details":{"feature_id":518630,"feature_type":"Movie","year":1967,"title":"Casino Royale","movie_name":"1967 - Casino Royale","imdb_id":61452,"tmdb_id":12208},"url":"https://www.opensubtitles.com/ro/subtitles/legacy/3650579","related_links":{"label":"All subtitles for Casino Royale","url":"https://www.opensubtitles.com/ro/movies/1967-casino-royale","img_url":"https://s9.osdb.link/features/0/3/6/518630.jpg"},"files":[{"file_id":579397,"cd_number":1,"file_name":"Casino Royale - oo7.sub"}],"moviehash_match":true}},{"id":"522774","type":"subtitle","attributes":{"subtitle_id":"522774","language":"es","download_count":1003,"new_download_count":1,"hearing_impaired":false,"hd":false,"fps":25.0,"votes":2,"ratings":9.5,"from_trusted":false,"foreign_parts_only":false,"upload_date":"2003-12-18T23:00:00Z","ai_translated":false,"machine_translated":false,"release":"Casino Royale (1967)","comments":null,"legacy_subtitle_id":59217,"uploader":{"uploader_id":8092,"name":"ShooCat (a)","rank":"bronze member"},"feature_details":{"feature_id":518630,"feature_type":"Movie","year":1967,"title":"Casino Royale","movie_name":"1967 - Casino Royale","imdb_id":61452,"tmdb_id":12208},"url":"https://www.opensubtitles.com/es/subtitles/legacy/59217","related_links":{"label":"All subtitles for Casino Royale","url":"https://www.opensubtitles.com/es/movies/1967-casino-royale","img_url":"https://s9.osdb.link/features/0/3/6/518630.jpg"},"files":[{"file_id":577519,"cd_number":1,"file_name":"Casino Royale (SPA).srt"}],"moviehash_match":true}},{"id":"525409","type":"subtitle","attributes":{"subtitle_id":"525409","language":"es","download_count":432,"new_download_count":2,"hearing_impaired":false,"hd":false,"fps":25.0,"votes":0,"ratings":0.0,"from_trusted":false,"foreign_parts_only":false,"upload_date":"2014-05-04T22:40:02Z","ai_translated":false,"machine_translated":false,"release":"James Bond - 007 - Casino Royale -1967","comments":"","legacy_subtitle_id":5657430,"uploader":{"uploader_id":3282,"name":"os-auto","rank":"Application Developers"},"feature_details":{"feature_id":518630,"feature_type":"Movie","year":1967,"title":"Casino Royale","movie_name":"1967 - Casino Royale","imdb_id":61452,"tmdb_id":12208},"url":"https://www.opensubtitles.com/es/subtitles/legacy/5657430","related_links":{"label":"All subtitles for Casino Royale","url":"https://www.opensubtitles.com/es/movies/1967-casino-royale","img_url":"https://s9.osdb.link/features/0/3/6/518630.jpg"},"files":[{"file_id":580507,"cd_number":1,"file_name":"James Bond - 007 - Casino Royale -1967-spa.srt"}],"moviehash_match":true}}]}'; 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