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

/
/
gm

Test String

Code Generator

Generated Code

use strict; my $str = 'WEBVTT NOTE duration:"02:09:15.8840000" NOTE language:en-us NOTE Confidence: 0.881069481372833 d8d8fcb9-ccb1-41f2-a75e-0c3088e95dc2 00:00:01.720 --> 00:00:07.798 So we\'re going to try to NOTE Confidence: 0.881069481372833 a8f8cc83-48c4-4acc-881b-85b37c73b42c 00:00:07.798 --> 00:00:13.876 to use Microsoft Teams next week, NOTE Confidence: 0.881069481372833 d2738b5d-b7ee-4b58-8388-4b7524c3c563 00:00:13.876 --> 00:00:19.954 so will post it as a NOTE Confidence: 0.802268326282501 baab9c8e-f018-48a2-a355-b23eb29174e9 00:00:19.954 --> 00:00:25.728 teams meeting. If you\'ve never used prosoft teams before, it\'s NOTE Confidence: 0.932209372520447 73231caa-7ae7-4046-acdf-c6691c7c3c41 00:00:25.728 --> 00:00:30.013 it\'s. Basically the same thing, just a little more stable. NOTE Confidence: 0.825244784355164 3ab6c4cb-9d70-4140-8356-c0f7c2316874 00:00:30.730 --> 00:00:35.224 Then they will put the link in Quercus and send it out as an'; my $regex = qr/[0-9]/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