Regular Expressions 101

Save & Share

  • Regex Version: ver. 2
  • 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
No Match

/
/
gm

Test String

Substitution

Processing...

Code Generator

Generated Code

$re = '/^(\s*"[^"]+")/m'; $str = '"sound_materials" { "common" { "value" "0" "start_drag_sound" "ui.inv_pickup" "end_drag_sound" "ui.inv_drop" "equip_sound" "ui.inv_equip" } "chest" { "value" "1" "start_drag_sound" "ui.inv_pickup_chest" "end_drag_sound" "ui.inv_drop_chest" } "pennant" { "value" "2" "start_drag_sound" "ui.inv_pickup_pennant" "end_drag_sound" "ui.inv_drop_pennant" } "key" { "value" "3" "start_drag_sound" "ui.inv_pickup_key" "end_drag_sound" "ui.inv_drop_key" } "metal_small" { "value" "4" "start_drag_sound" "ui.inv_pickup_metalsmall" "end_drag_sound" "ui.inv_drop_metalsmall" "equip_sound" "ui.inv_equip_metalsmall" } "metal_armor" { "value" "5" "start_drag_sound" "ui.inv_pickup_metalarmour" "end_drag_sound" "ui.inv_drop_metalarmour" "equip_sound" "ui.inv_equip_metalarmour" } "metal_blade" { "value" "6" "start_drag_sound" "ui.inv_pickup_metalblade" "end_drag_sound" "ui.inv_drop_metalblade" "equip_sound" "ui.inv_equip_metalblade" } "metal_heavy" { "value" "7" "start_drag_sound" "ui.inv_pickup_metalheavy" "end_drag_sound" "ui.inv_drop_metalheavy" "equip_sound" "ui.inv_equip_metalheavy" } "staff_or_blunt" { "value" "8" "start_drag_sound" "ui.inv_pickup_staff" "end_drag_sound" "ui.inv_drop_staff" "equip_sound" "ui.inv_equip_staff" } "robes" { "value" "9" "start_drag_sound" "ui.inv_pickup_robes" "end_drag_sound" "ui.inv_drop_robes" "equip_sound" "ui.inv_equip_robes" } "leather" { "value" "10" "start_drag_sound" "ui.inv_pickup_leather" "end_drag_sound" "ui.inv_drop_leather" "equip_sound" "ui.inv_equip_leather" } "quiver" { "value" "11" "start_drag_sound" "ui.inv_pickup_quiver" "end_drag_sound" "ui.inv_drop_quiver" "equip_sound" "ui.inv_equip_quiver" } "stone" { "value" "12" "start_drag_sound" "ui.inv_pickup_stone" "end_drag_sound" "ui.inv_drop_stone" "equip_sound" "ui.inv_equip_stone" } "wood" { "value" "13" "start_drag_sound" "ui.inv_pickup_wood" "end_drag_sound" "ui.inv_drop_wood" "equip_sound" "ui.inv_equip_wood" } "bone" { "value" "14" "start_drag_sound" "ui.inv_pickup_bone" "end_drag_sound" "ui.inv_drop_bone" "equip_sound" "ui.inv_equip_bone" } "jug" { "value" "15" "start_drag_sound" "ui.inv_pickup_jug" "end_drag_sound" "ui.inv_drop_jug" "equip_sound" "ui.inv_equip_jug" } "gun" { "value" "16" "start_drag_sound" "ui.inv_pickup_gun" "end_drag_sound" "ui.inv_drop_gun" "equip_sound" "ui.inv_equip_gun" } "highvalue" { "value" "17" "start_drag_sound" "ui.inv_pickup_highvalue" "end_drag_sound" "ui.inv_drop_highvalue" "equip_sound" "ui.inv_equip_highvalue" } }'; $subst = "\1:"; $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