Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
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
Processing...

Test String

Substitution
Processing...

Code Generator

Generated Code

$re = '/<(\S+) tag="([^"]+)">([^<]+)<\/(?1)>/m'; $str = '<image tag="plan">http://img.nmarket.pro/photo/pid/E2087273-BDC1-4717-9F2E-20F6A76E0479/?v=1&amp;cid=2415&amp;pid=E2087273-BDC1-4717-9F2E-20F6A76E0479&amp;wpsid=51&amp;hash=031b3173e71427e3673247f8a80135c8</image> <image tag="houseuncategorized">http://img.nmarket.pro/photo/pid/1C372F09-3440-49FE-9A6D-048EF51B5F73/?v=1&amp;cid=2415&amp;pid=1C372F09-3440-49FE-9A6D-048EF51B5F73&amp;wpsid=51&amp;hash=810aea88a716dfff20ae5c182bf38888</image> <image tag="houseuncategorized">http://img.nmarket.pro/photo/pid/3628BB57-3D4C-43A9-AD00-843E5D5F657F/?v=1&amp;cid=2415&amp;pid=3628BB57-3D4C-43A9-AD00-843E5D5F657F&amp;wpsid=51&amp;hash=abf93d04775994f55fe82eb84dfad54e</image> <image tag="houseuncategorized">http://img.nmarket.pro/photo/pid/3EDBD70B-7393-4A93-9BAD-54B32DA49EEF/?v=1&amp;cid=2415&amp;pid=3EDBD70B-7393-4A93-9BAD-54B32DA49EEF&amp;wpsid=51&amp;hash=0565037ec9d45e15d0c84df34100e3dc</image> <image tag="houseuncategorized">http://img.nmarket.pro/photo/pid/2C8FE09E-AE07-4E13-89F0-B4695A7428AF/?v=1&amp;cid=2415&amp;pid=2C8FE09E-AE07-4E13-89F0-B4695A7428AF&amp;wpsid=51&amp;hash=f1a03336866c285fb16a604708a9c15e</image> <image tag="housemain">http://img.nmarket.pro/photo/pid/0CCFA7EA-3757-4740-A721-BF75DEAAB11C/?v=1&amp;cid=2415&amp;pid=0CCFA7EA-3757-4740-A721-BF75DEAAB11C&amp;wpsid=51&amp;hash=c69a5cf80cd48f6ccc4b68c077d5f301</image> <image tag="complexscheme">http://img.nmarket.pro/photo/pid/29E51673-697F-4F38-9F9B-1DF28B22F3A1/?v=1&amp;cid=2415&amp;pid=29E51673-697F-4F38-9F9B-1DF28B22F3A1&amp;wpsid=51&amp;hash=c826f221b1d372d0defbc04c857f01f3</image> <image tag="floorplan">http://img.nmarket.pro/photo/pid/F0DB967A-895F-4740-9FFE-FF3F100519EE/?v=1&amp;cid=2415&amp;pid=F0DB967A-895F-4740-9FFE-FF3F100519EE&amp;wpsid=51&amp;hash=15c82a24c7c0c6bacd8b1551c44ca0ec</image> <parking tag="hello">world</class> '; $subst = "<$1><$2>$3</$2></$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