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

/
/
gs

Test String

Code Generator

Generated Code

$re = '/Track number:(?:.(?!Track number:))*subtitles/s'; $str = '+ EBML head |+ EBML version: 1 |+ EBML read version: 1 |+ EBML maximum ID length: 4 |+ EBML maximum size length: 8 |+ Doc type: matroska |+ Doc type version: 2 |+ Doc type read version: 2 + Segment, size 467658217 |+ Seek head (subentries will be skipped) |+ EbmlVoid (size: 4029) |+ Segment information | + Timecode scale: 1000000 | + Muxing application: libebml v1.0.0 + libmatroska v1.0.0 | + Writing application: mkvmerge v4.0.0 (\'The Stars were mine\') built on Jun 6 2010 16:18:42 | + Duration: 5819.819s (01:36:59.819) | + Date: Sat Jul 3 16:19:00 2010 UTC | + Segment UID: 0xae 0x0c 0xfb 0x11 0x90 0x39 0x93 0x1b 0x89 0xa4 0xb1 0xaa 0xa0 0x79 0x3d 0x42 |+ Segment tracks | + A track | + Track number: 1 (track ID for mkvmerge & mkvextract: 0) | + Track UID: 863185562 | + Track type: video | + Default flag: 0 | + Lacing flag: 0 | + MinCache: 1 | + Codec ID: V_MPEG4/ISO/AVC | + CodecPrivate, length 41 (h.264 profile: High @L3.1) | + Default duration: 41.708ms (23.976 frames/fields per second for a video track) | + Language: und | + Video track | + Pixel width: 1280 | + Pixel height: 534 | + Display width: 1280 | + Display height: 534 | + A track | + Track number: 2 (track ID for mkvmerge & mkvextract: 1) | + Track UID: 3319793313 | + Track type: audio | + Default flag: 0 | + Codec ID: A_AAC | + CodecPrivate, length 7 | + Default duration: 42.667ms (23.438 frames/fields per second for a video track) | + Audio track | + Sampling frequency: 24000 | + Channels: 2 | + Output sampling frequency: 48000 | + A track | + Track number: 3 (track ID for mkvmerge & mkvextract: 2) | + Track UID: 1382186431 | + Track type: subtitles | + Lacing flag: 0 | + Codec ID: S_TEXT/UTF8 |+ EbmlVoid (size: 1122) |+ Chapters | + EditionEntry | + EditionFlagHidden: 0 | + EditionFlagDefault: 0 | + EditionUID: 2614993839 | + ChapterAtom | + ChapterUID: 2912241034 | + ChapterTimeStart: 00:00:00.097000000 | + ChapterFlagHidden: 0 | + ChapterFlagEnabled: 1 | + ChapterDisplay | + ChapterString: 00:00:00.097 | + ChapterLanguage: eng |+ EbmlVoid (size: 101) |+ Cluster |+ | + A track | + Track number: 2 (track ID for mkvmerge & mkvextract: 1) | + Track UID: 3319793313 | + Track type: audio | + Default flag: 0 | + Codec ID: A_AAC | + CodecPrivate, length 7 | + Default duration: 42.667ms (23.438 frames/fields per second for a video track) | + Audio track | + Sampling frequency: 24000 | + Channels: 2 | + Output sampling frequency: 48000 + EBML head |+ EBML version: 1 |+ EBML read version: 1 |+ EBML maximum ID length: 4 |+ EBML maximum size length: 8 |+ Doc type: matroska |+ Doc type version: 2 |+ Doc type read version: 2 + Segment, size 467658217 |+ Seek head (subentries will be skipped) |+ EbmlVoid (size: 4029) |+ Segment information | + Timecode scale: 1000000 | + Muxing application: libebml v1.0.0 + libmatroska v1.0.0 | + Writing application: mkvmerge v4.0.0 (\'The Stars were mine\') built on Jun 6 2010 16:18:42 | + Duration: 5819.819s (01:36:59.819) | + Date: Sat Jul 3 16:19:00 2010 UTC | + Segment UID: 0xae 0x0c 0xfb 0x11 0x90 0x39 0x93 0x1b 0x89 0xa4 0xb1 0xaa 0xa0 0x79 0x3d 0x42 |+ Segment tracks | + A track | + Track number: 1 (track ID for mkvmerge & mkvextract: 0) | + Track UID: 863185562 | + Track type: video | + Default flag: 0 | + Lacing flag: 0 | + MinCache: 1 | + Codec ID: V_MPEG4/ISO/AVC | + CodecPrivate, length 41 (h.264 profile: High @L3.1) | + Default duration: 41.708ms (23.976 frames/fields per second for a video track) | + Language: und | + Video track | + Pixel width: 1280 | + Pixel height: 534 | + Display width: 1280 | + Display height: 534 | + A track | + Track number: 2 (track ID for mkvmerge & mkvextract: 1) | + Track UID: 3319793313 | + Track type: audio | + Default flag: 0 | + Codec ID: A_AAC | + CodecPrivate, length 7 | + Default duration: 42.667ms (23.438 frames/fields per second for a video track) | + Audio track | + Sampling frequency: 24000 | + Channels: 2 | + Output sampling frequency: 48000 | + A track | + Track number: 3 (track ID for mkvmerge & mkvextract: 2) | + Track UID: 1382186431 | + Track type: subtitles | + Lacing flag: 0 | + Codec ID: S_TEXT/UTF8 |+ EbmlVoid (size: 1122) |+ Chapters | + EditionEntry | + EditionFlagHidden: 0 | + EditionFlagDefault: 0 | + EditionUID: 2614993839 | + ChapterAtom | + ChapterUID: 2912241034 | + ChapterTimeStart: 00:00:00.097000000 | + ChapterFlagHidden: 0 | + ChapterFlagEnabled: 1 | + ChapterDisplay | + ChapterString: 00:00:00.097 | + ChapterLanguage: eng |+ EbmlVoid (size: 101) |+ Cluster |+ | + A track | + Track number: 2 (track ID for mkvmerge & mkvextract: 1) | + Track UID: 3319793313 | + Track type: audio | + Default flag: 0 | + Codec ID: A_AAC | + CodecPrivate, length 7 | + Default duration: 42.667ms (23.438 frames/fields per second for a video track) | + Audio track | + Sampling frequency: 24000 | + Channels: 2 | + Output sampling frequency: 48000 '; 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