Regular Expressions 101

Save & Share

  • Regex Version: ver. 8
  • 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

/
/
img

Test String

Code Generator

Generated Code

$re = '/(you (?<action>fire|poach|snipe) an?|your) (?<prefix>[^\.!]*? )?(?<ammo>arrow|bolt|stone shard|shard|rock|sphere|clump|coral|fist|holder|lump|patella|pellet|pulzone|quadrello|quarrel|quill|stone|stopper|verretto|blowgun dart|crumb|spine|mantrap spike|tiny dragon|icicle|fang|scale|grey-black spike|bacon strip|page|naga|thorn|fragment)s?(?<suffix> [^\.!]*?)?? (at|passes through)/im'; $str = 'Your Sunderstone shard passes through the revenant conscript with no effect and falls to your feet! < You fire a blunt-tipped arrow with camel stripes at a quartz gargoyle. A quartz gargoyle evades, just stepping out of harm\'s way. The blunt-tipped arrow hits a wall and falls to your feet! [You\'re solidly balanced with no advantage.] < You fire a blunt-tipped arrow with absinthe-green stripes at an Endrus serpent. An Endrus serpent dodges, ducking in the nick of time. The blunt-tipped arrow lands nearby! [You\'re adeptly balanced and in better position.] < You fire a senci stone shard at an Endrus serpent. An Endrus serpent evades, barely twisting out of harm\'s reach. The stone shard lands nearby! [You\'re nimbly balanced and in dominating position.] [Roundtime 1 sec.] < You fire a boar-tusk arrow at an Endrus serpent. An Endrus serpent evades, ducking in the nick of time. The boar-tusk arrow lands nearby! [You\'re adeptly balanced and overwhelming opponent.] [Roundtime 1 sec.] < Moving with the precision of a mongoose, you snipe a blunt-tipped arrows with absinthe-green stripe at a quartz gargoyle. A quartz gargoyle attempts to evade, avoiding only some of the blow. The arrow lands a massive strike (11/23) that etches a light cut into the right side of the chest. The blunt-tipped arrow falls to the ground! [You\'re nimbly balanced and in good position.] < Driving in with an overwhelming assault, you poach an ice-adder arrow at a granite gargoyle. A granite gargoyle fails to evade, twisting partially away from much of the blow. The arrow lands a massive strike (11/23) that nicks the gargoyle\'s left forearm. The ice-adder arrow lodges itself shallowly into the granite gargoyle! [You\'re solidly balanced with no advantage.] [Roundtime 1 sec.] < Moving with indomitable grace, you fire a blunt-tipped bolts with lavender chevron at a copperhead viper. A copperhead viper fails to evade, mis-stepping and blundering into the blow. The bolt lands a powerful strike (10/22) that bloodies the viper\'s lip, lightly stunning it. The blunt-tipped bolt falls to the ground! [You\'re bruised, nimbly balanced and in dominating position.] [Roundtime 1 sec.] < Driving in with exacting precision, you fire a pretty pink tiny dragon with a spiked tail at a ship\'s rat. A ship\'s rat attempts to dodge, leaning wrong and blundering into the blow. The tiny dragon lands a cataclysmic strike (22/23) (Did the Greater Fist just erupt again?) that painfully mashes the left leg. < Driving in with exacting precision, you fire a bacon strip at a ship\'s rat. A ship\'s rat attempts to dodge, leaning wrong and blundering into the blow. The tiny dragon lands a cataclysmic strike (22/23) (Did the Greater Fist just erupt again?) that painfully mashes the left leg. < You fire a matte indurium sphere at an arthelun cabalist. An arthelun cabalist dodges, leaning to one side with no room to spare. The matte indurium sphere hits a wall and falls to your feet! [You\'re winded, mighty, nimbly balanced and in better position.] [Roundtime 1 sec.] < Moving with amazing force and guile, you fire a Sunderstone shard at a storm bull. A storm bull attempts to dodge, taking the full blow. The shard lands a spine-rattling strike that rips the right arm clean off at the shoulder. The Sunderstone shard falls to the ground! A storm bull expires with a bellow and a crackle of electricity. The shimmering ethereal shield fades from around a storm bull. [You\'re nimbly balanced] < Moving with amazing force and guile, you fire a delicious cupcake crumb decorated with sprinkles at a storm bull. A storm bull attempts to dodge, taking the full blow. The crumb lands a spine-rattling strike that rips the right arm clean off at the shoulder. The cupcake crumb falls to the ground! A storm bull expires with a bellow and a crackle of electricity. The shimmering ethereal shield fades from around a storm bull. [You\'re nimbly balanced] Your attempt is slightly hindered by your demonscale shield. < You fire a lemon-striped arrow at a giant bear. A giant bear dodges, ducking in the nick of time. The lemon-striped arrow falls to your feet! [You\'re nimbly balanced and have slight advantage.] Your attempt is slightly hindered by your demonscale shield. < Moving with dominating grace, you fire a lemon-striped arrow at a giant bear. A giant bear attempts to dodge, avoiding only some of the blow. The arrow lands an extremely heavy hit (9/22) that deeply bruises the right bicep, lightly stunning it. The lemon-striped arrow falls to the ground! [You\'re nimbly balanced and in good position.] [Roundtime 1 sec.]'; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); // Print the entire match result var_dump($matches);

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