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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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

Substitution

Processing...

Code Generator

Generated Code

$re = '/^(\|-uint32_t \(\[\d*\]\) \= (\d*) \(\dx\w+\))/m'; $str = '|-uint32_t ([0]) = 2865385407 (0xaaca4fbf) |-uint32_t ([1]) = 2865397407 (0xaaca7e9f) |-uint32_t ([2]) = 2865409407 (0xaacaad7f) |-uint32_t ([3]) = 2865421407 (0xaacadc5f) |-uint32_t ([4]) = 2865433407 (0xaacb0b3f) |-uint32_t ([5]) = 2865445407 (0xaacb3a1f) |-uint32_t ([6]) = 2865457407 (0xaacb68ff) |-uint32_t ([7]) = 2865469407 (0xaacb97df) |-uint32_t ([8]) = 2865481407 (0xaacbc6bf) |-uint32_t ([9]) = 2865493407 (0xaacbf59f) |-uint32_t ([10]) = 2865505407 (0xaacc247f) |-uint32_t ([11]) = 2865517407 (0xaacc535f) |-uint32_t ([12]) = 2865529407 (0xaacc823f) |-uint32_t ([13]) = 2865541408 (0xaaccb120) |-uint32_t ([14]) = 2865553408 (0xaacce000) |-uint32_t ([15]) = 2865565408 (0xaacd0ee0) |-uint32_t ([16]) = 2865577408 (0xaacd3dc0) |-uint32_t ([17]) = 2865589408 (0xaacd6ca0) |-uint32_t ([18]) = 2865601408 (0xaacd9b80) |-uint32_t ([19]) = 2865613408 (0xaacdca60) |-uint32_t ([20]) = 2865625408 (0xaacdf940) |-uint32_t ([21]) = 2865637408 (0xaace2820) |-uint32_t ([22]) = 2865649408 (0xaace5700) |-uint32_t ([23]) = 2865661408 (0xaace85e0) |-uint32_t ([24]) = 2865673408 (0xaaceb4c0) |-uint32_t ([25]) = 2865685408 (0xaacee3a0) |-uint32_t ([26]) = 2865697408 (0xaacf1280) |-uint32_t ([27]) = 2865709408 (0xaacf4160) |-uint32_t ([28]) = 2865721408 (0xaacf7040) |-uint32_t ([29]) = 2865733409 (0xaacf9f21) |-uint32_t ([30]) = 2865745409 (0xaacfce01) |-uint32_t ([31]) = 2865757409 (0xaacffce1) |-uint32_t ([32]) = 2865769409 (0xaad02bc1) |-uint32_t ([33]) = 2865781409 (0xaad05aa1) |-uint32_t ([34]) = 2865793409 (0xaad08981) |-uint32_t ([35]) = 2865805409 (0xaad0b861) |-uint32_t ([36]) = 2865817409 (0xaad0e741) |-uint32_t ([37]) = 2865829409 (0xaad11621) |-uint32_t ([38]) = 2865841409 (0xaad14501) |-uint32_t ([39]) = 2865853409 (0xaad173e1) '; $subst = "\2"; $result = preg_replace($re, $subst, $str); echo "The result of the substitution is ".$result;

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