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

/
/
gumi

Test String

Code Generator

Generated Code

use strict; my $str = 'Match all characters between two strings with dotall mode to match across line breaks Duis sem mi, rhoncus ut enim quis, ultricies posuere libero. Etiam et euismod dolor, at ornare lorem. Praesent iaculis pellentesque felis, sit amet interdum ex ultricies id. Nam eu mattis nisi. Sed et odio risus. Proin fermentum in justo non consequat. Pellentesque pellentesque augue sed erat porta gravida. In a magna at metus suscipit sodales non eget massa. Maecenas eu turpis non nisl semper ultricies. Duis rhoncus imperdiet sapien, vitae posuere erat tempor id. Vestibulum in enim fermentum purus tempor maximus tempus quis ex. Maecenas vitae felis ac elit semper blandit. Suspendisse neque eros, vestibulum nec ultrices at, sagittis eget ex. Aenean feugiat libero nunc, sit amet commodo turpis tristique luctus. Sed sodales diam at urna viverra, nec ultrices enim imperdiet. startLorem ipsum dolor sit amet, consectetur adipiscing elit. Nulla velit diam, vehicula eget nunc at, aliquet mattis velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nam quis sollicitudin augue. Maecenas a auctor nibh. Pellentesque aliquam nulla sit amet posuere laoreet. Nunc lorem massa, vehicula ac vehicula ac, varius vel est. Proin sed mattis dolor. Cras quis enim non nisl ultrices rhoncus in ut nisl. endCurabitur venenatis ullamcorper ullamcorper. Praesent in mi non mi bibendum lobortis at vel est. Mauris luctus varius justo, non rhoncus sem tristique quis. Aenean ac metus commodo felis pharetra dapibus. Integer hendrerit, enim ac varius sagittis, ipsum lacus euismod elit, sed sagittis tortor purus nec sapien. Morbi luctus risus quam, nec imperdiet nibh pulvinar id. Pellentesque pretium posuere ligula, id ullamcorper sapien placerat at. Nulla mattis tristique nisi id ornare. Cras at orci magna. Praesent interdum id est vitae feugiat. Praesent vulputate, tortor at eleifend venenatis, leo turpis malesuada mauris, non lobortis urna velit fringilla lacus.'; my $regex = qr/(?s)(?<=start).*?(?=end)/umip; 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