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

/
/
gm

Test String

Code Generator

Generated Code

use strict; my $str = 'MD5 Hashes: dfbf02e00c4bc7c737a4479a6bcc2662 78fd94b5de88a8c32a1521a9edf3f908 d1dfaf1d502252eede2b4d492e990be0 4a6d82b24008d338941a1a7f9369742d 9ec1730ec98c161360b13aae5d46ad12 SHA1 Hashes: 82ad7d8314ed1a73dac3de38970d8717e9923e26 ddda41e9fcec08e0feb68629b57cbe06ce12ac16 68b7122f58f0cdb3b20e1f3eac1fed6e1036061b 634dbc333d264f22c02402fc568d4a5cd3bb3b0e 74af0c22f50e4c4c1b1dead321649e6022a2ac24 SHA256 Hashes: a734caac2c040c629ff86b87163eb92f2ec124f95a3f3ecd0530db7159bc404a b75c5c00b9e1b93c7cb63eab0266ade210b5e537c4374cedafb9f30569cc2202 afa97cbdfd095037792305bcc0a63e07df645d7540c94ec73f7954595336992d f67ac28d075c22db46fba3f400fabe820194dc85280d06c7d16326c88a31f7f8 f6e99ce69331f6aa18a34d59aec33fb59abfdda8ee381406245ef727dd96d45b SHA512 Hashes: cc05fe2373f2750aa969d2cb73b9e9db5550091400df6bef1d17c2e03df5b4531964b70ef84bcc8e3aae7d931fc53695f9642bc1480a00b75f669fc4025fb41f 13d23518b639548b29a86caf178d2042ccd7983c7197368a25e077c4706c38752272f3f4a49e6d9738358d6a2a04b253f7996c8633d4fd4ac17980455a32dc5e 0871723a28839c68b0c4c0212a8877b461226c7a4e060f108fc33ef8c95db7b2c21a01e8943880f63f68276ccc82c4f28d1e0ef77ae4f9d1393b2097465d42b9 ea0b231c71ee9433ba16a0445fbff1c37885753d3f0fe6b80be56f50956cc43b6cbef8786ce80899afb1577012c211f675cae57348b8d6a290a8baed227dacdd 81bf9797ebcabafc3e9dffa7cf8d65f1cf76a41f49b5980db528abbb54c132c5407ba60a7d6256db8e20fe58508296188bf6ccc84331bbcedd9b5cafe77e5e62'; my $regex = qr/\b[a-fA-F0-9]{32,128}\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