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
No Match

r"
"
gm

Test String

Code Generator

Generated Code

use strict; my $str = 'ffmpeg version 4.2.2 Copyright (c) 2000-2019 the FFmpeg developers built with Apple clang version 11.0.0 (clang-1100.0.33.17) configuration: --prefix=/usr/local/Cellar/ffmpeg/4.2.2_3 --enable-shared --enable-pthreads --... [silencedetect @ 0x7fdd82d011c0] silence_start: 0 frame= 112 fps=0.0 q=-0.0 size=N/A time=00:00:05.00 bitrate=N/A speed=9.96x [blackdetect @ 0x7fdd82e06580] black_start:0 black_end:5 black_duration:5 [silencedetect @ 0x7fdd82d011c0] silence_end: 5.06285 | silence_duration: 5.06285 frame= 211 fps=210 q=-0.0 size=N/A time=00:00:09.00 bitrate=N/A speed=8.97x frame= 319 fps=212 q=-0.0 size=N/A time=00:00:13.00 bitrate=N/A speed=8.63x frame= 427 fps=213 q=-0.0 size=N/A time=00:00:17.08 bitrate=N/A speed=8.51x frame= 537 fps=214 q=-0.0 size=N/A time=00:00:22.00 bitrate=N/A speed=8.77x frame= 650 fps=216 q=-0.0 size=N/A time=00:00:26.00 bitrate=N/A speed=8.63x frame= 761 fps=217 q=-0.0 size=N/A time=00:00:31.00 bitrate=N/A speed=8.82x frame= 874 fps=218 q=-0.0 size=N/A time=00:00:35.00 bitrate=N/A speed=8.71x frame= 980 fps=217 q=-0.0 size=N/A time=00:00:39.20 bitrate=N/A speed=8.67x ... frame= 5680 fps=213 q=-0.0 size=N/A time=00:03:47.20 bitrate=N/A speed=8.53x [silencedetect @ 0x7fdd82d011c0] silence_start: 227.733 [silencedetect @ 0x7fdd82d011c0] silence_end: 229.051 | silence_duration: 1.3184 [silencedetect @ 0x7fdd82d011c0] silence_start: 229.051 [blackdetect @ 0x7fdd82e06580] black_start:229.28 black_end:230.24 black_duration:0.96 frame= 5757 fps=214 q=-0.0 Lsize=N/A time=00:03:50.28 bitrate=N/A speed=8.54x video:3013kB audio:43178kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: unknown [silencedetect @ 0x7fdd82d011c0] silence_end: 230.28 | silence_duration: 1.22856'; my $regex = qr/\b(?:silence|black)_(?:start|end|duration):\s*\d+(?:\.\d+)?\b/mp; if ( $str =~ /$regex/g ) { print "Whole match is ${^MATCH} and its start/end positions can be obtained via \$-[0] and \$+[0]\n"; # print "Capture Group 1 is $1 and its start/end positions can be obtained via \$-[1] and \$+[1]\n"; # print "Capture Group 2 is $2 ... and so on\n"; } # ${^POSTMATCH} and ${^PREMATCH} are also available with the use of '/p' # Named capture groups can be called via $+{name}

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 Perl, please visit: http://perldoc.perl.org/perlre.html