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
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

/
/
gsi

Test String

Substitution

Processing...

Code Generator

Generated Code

$re = '/.*?Name: (?<name>.*?)\nversion: (?<num>.*?)\n.*?created on: (?<date>.*?)\n.*?/si'; $str = 'Loading repository data... Reading installed packages... Information for patch sdksp3-rpm-201406: Name: sdksp3-rpm-201406 Version: 9435 Arch: noarch Vendor: maint-coord@suse.de Status: Needed Category: recommended Created On: Thu Jun 26 11:27:51 2014 Reboot Required: No Package Manager Restart Required: Yes Interactive: No Summary: YOU update for popt Description: This update for RPM provides the following fixes and enhancements: * Add query support for the new weak dependency tags used in SLE 12. (bnc#884373) * Remove harmful --target option passing from the configure macro. (bnc#870358) * Disable broken ldconfig skipping code. (bnc#725478) Additionally, one issue was fixed in the rpm-python sub-package: * Return a PyLong for installsize and archivesize if a PyInt would be negative. This could make createrepo(8) generate repository metadata with negative sizes for some packages. (bnc#882489) Provides: patch:sdksp3-rpm-201406 == 9435 Conflicts: popt-devel.x86_64 < 1.7-37.58.1 rpm-32bit.x86_64 < 4.4.2.3-37.58.1 rpm-devel.x86_64 < 4.4.2.3-37.58.1 Loading repository data... Reading installed packages... Information for patch sdksp3-rpm-201501: Name: sdksp3-rpm-201501 Version: 10143 Arch: noarch Vendor: maint-coord@suse.de Status: Needed Category: recommended Created On: Fri Jan 9 08:15:33 2015 Reboot Required: No Package Manager Restart Required: Yes Interactive: No Summary: Recommended update for rpm Description: This update for "rpm" fixes installation of packages when there are spaces in the path or file name and the option "--noglob" is used. Provides: patch:sdksp3-rpm-201501 == 10143 Conflicts: popt-devel.x86_64 < 1.7-37.62.9 rpm-32bit.x86_64 < 4.4.2.3-37.62.9 rpm-devel.x86_64 < 4.4.2.3-37.62.9 Loading repository data... Reading installed packages... Information for patch sdksp3-softwaremgmt-201503: Name: sdksp3-softwaremgmt-201503 Version: 10576 Arch: noarch Vendor: maint-coord@suse.de Status: Needed Category: recommended Created On: Tue Apr 7 09:29:23 2015 Reboot Required: No Package Manager Restart Required: Yes Interactive: No Summary: YOU update for the Software Update Stack Description: This collective update for the Software Update Stack provides several fixes and enhancements. libsatsolver: * Support product end-of-life attribute. (FATE#300591) libzypp: * Improve conflict message for locked packages. (bsc#828631) * Add Product::endOfLife attribute. (FATE#316172, FATE#300591) PackageKit: * When a proxy server is configured, a default route is not mandatory. (bsc#910462) rpm: * Allow noscripts and notriggers on verify. (bsc#803669) yast2-pkg-bindings: * Use alias from URL query parameter if present. (bsc#892431) zypper: * A date limit must ignore newer patch candidates. (bsc#919709) * Show locked packages in zypper summary. (FATE#318256) * Refresh plugin services on \'lr\' \'ls -r\' and \'ref\'. (bsc#893294, FATE#317863) * Enhance \'Digest verification failed\' dialog. (FATE#315008) * Add Product::endOfLife attribute. (FATE#316172, FATE#300591) Provides: patch:sdksp3-softwaremgmt-201503 == 10576 Conflicts: PackageKit-devel.x86_64 < 0.3.14-2.30.11 libpackagekit-glib10-devel.x86_64 < 0.3.14-2.30.11 libpackagekit-qt10.x86_64 < 0.3.14-2.30.11 libpackagekit-qt10-devel.x86_64 < 0.3.14-2.30.11 libsatsolver-devel.x86_64 < 0.17.9-0.5.2 libzypp-devel.x86_64 < 9.38.4-0.7.10 popt-devel.x86_64 < 1.7-37.63.64.1 rpm-32bit.x86_64 < 4.4.2.3-37.63.64.1 rpm-devel.x86_64 < 4.4.2.3-37.63.64.1 ruby-satsolver.x86_64 < 0.44.5-0.5.194 yast2-pkg-bindings-devel-doc.noarch < 2.17.59.2-0.8.13 Loading repository data... Reading installed packages... '; $subst = "\g<name> \g<num> \g<date>\n"; $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