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 = '/(.*Request.*\[(?P<req_ip>.*)\:.*\].*GZIP)\n(.*)\n(.*)\n(.*Play.*\'(?P<watched>.*)\'.*)\n(.*User is\s(?P<who>.*)\s\(.*)\n(.*Device is(?P<device>.*)\.)\n(.*)\n(.*Completed.*\=(?P<movie_time>\d+)\&k.*\&time\=(?P<played_time>\d+)\s\(.*)/'; $str = '[2016-07-03 13:45:04,777] INFO PlayQueueInputStream - brent listening to "Firehouse/Love Of A Lifetime.MP3" [2016-07-02 21:21:10,615] INFO TranscodeInputStream - Starting transcoder: [/var/subsonic/transcode/ffmpeg] [-i] [/pub/media/mp3/Rock/TedNugent/Cat Scratch Fever/01 Cat Scratch Fever.wma] [-map] [0:0] [-b:a] [192k] [-v] [0] [-f] [mp3] [-] [2016-07-02 19:46:57,695] INFO TranscodeInputStream - Starting transcoder: [/var/subsonic/transcode/ffmpeg] [-i] [/pub/media/mp3/Rock/Kansas/01 Carry on Wayward Son.wma] [-map] [0:0] [-b:a] [192k] [-v] [0] [-f] [mp3] [-] [2016-07-02 19:28:31,635] INFO TranscodeInputStream - Starting transcoder: [/var/subsonic/transcode/ffmpeg] [-i] [/pub/media/mp3/Rock/Queen/Greatest Hits [Parlophone]/14 Flash.wma] [-map] [0:0] [-b:a] [192k] [-v] [0] [-f] [mp3] [-] [2016-07-02 22:12:39,647] INFO TranscodeInputStream - Starting transcoder: [/var/subsonic/transcode/ffmpeg] [-i] [/pub/media/mp3/Pop/Katy Perry/One of the Boys/02 I Kissed a Girl.m4a] [-ab] [192k] [-ar] [44100] [-ac] [2] [-v] [0] [-f] [mp3] [-] [2016-06-26 11:10:29,662] INFO TranscodeInputStream - Starting transcoder: [/var/subsonic/transcode/ffmpeg] [-i] [/pub/media/mp3/Christian/The Almost/2013 - Fear Inside Our Bones/03 - I\'m Down.flac] [-ab] [192k] [-ar] [44100] [-ac] [2] [-v] [0] [-f] [mp3] [-] [2016-07-04 19:47:41,874] INFO DownloadController - Downloading \'This is not a test (2015)/15. Like A Match (Garcia\'s Remix).mp3\' to Player 103 [caryn] INSERT INTO MEDIA_FILE VALUES(146130,\'/pub/media/mp3/Alternative/WorldParty/Goodbye Jumbo/06 And I Fell Back Alone.flac\',\'/pub/media/mp3/Alternative\',\'MUSIC\',\'flac\',\'06 And I Fell Back Alone\',\'Goodbye Jumbo\',\'WorldParty\',\'WorldParty\',NULL,NULL,NULL,NULL,NULL,FALSE,NULL,20943444,NULL,NULL,NULL,\'/pub/media/mp3/Alternative/WorldParty/Goodbye Jumbo\',0,NULL,NULL,\'2013-05-24 16:42:12.000000000\',\'2013-05-24 16:42:12.000000000\',\'2016-07-07 20:02:08.217000000\',\'1969-12-31 18:00:00.000000000\',TRUE,4) /*C2445758*/SET SCHEMA PUBLIC CONNECT USER SA DISCONNECT Jul 06, 2016 23:40:04 [0x7fdbf063b700] DEBUG - Loading Movie \'Batman v Superman: Dawn of Justice\' XML from /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Metadata/Movies/2/2d037fa20a5177c5442ca5d6fc44c7aea0940d6.bundle/Contents/_combined/ Jul 08, 2016 02:03:55 [0x7fdbf063b700] DEBUG - Loading Artist Liquido from XML file: /var/lib/plexmediaserver/Library/Application Support/Plex Media Server/Metadata/Artists/f/e4d9aa73581b1e97d433a111542ca12b5a97f29.bundle/Contents/_combined/Info.xml Adding xxxxxxxxxxxxxxxxxxxx as token for 42 sections for jefferyblake Jul 03, 2016 18:51:03 [0x7fdc0b125700] DEBUG - Request: [172.56.6.129:54338] GET /:/timeline?duration=6886122&key=/library/metadata/67850&playQueueItemID=2926&ratingKey=67850&state=playing&time=5286338 (13 live) TLS GZIP Jul 03, 2016 18:51:03 [0x7fdc0b125700] DEBUG - Auth: We found auth token (xxxxxxxxxxxxxxxxxxxx), enabling token-based authentication. Jul 03, 2016 18:51:03 [0x7fdc0b125700] DEBUG - Client [0B3645F6-539D-4428-86DB-E954F15992F9] reporting timeline state playing, progress of 5286338/6886122ms for guid=, ratingKey=67850 url=, key=/library/metadata/67850, containerKey=, metadataId=67850 Jul 03, 2016 18:51:03 [0x7fdc0b125700] DEBUG - Play progress on 67850 \'Pitch Perfect 2\' - got played 5286338 ms by account 4033586! Jul 03, 2016 18:51:03 [0x7fdc0b125700] DEBUG - [Now] User is deliaswaz (ID: 4033586) Jul 03, 2016 18:51:03 [0x7fdc0b125700] DEBUG - [Now] Device is iOS (Alan\'s iPhone). Jul 03, 2016 18:51:03 [0x7fdc0b125700] DEBUG - [Now] Updated play state for /library/metadata/67850. Jul 03, 2016 18:51:03 [0x7fdc0fbff700] DEBUG - Completed: [172.56.6.129:54338] GET /:/timeline?duration=6886122&key=/library/metadata/67850&playQueueItemID=2926&ratingKey=67850&state=playing&time=5286338 (13 live) TLS GZIP 6ms 203 bytes 200 (pipelined: 5)'; 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