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

/
/
gm

Test String

Code Generator

Generated Code

$re = '/(\w{3}\s\s\d{1,2} \d{2}:\d{2}:\d{2})\s(\S*)\s(\S*):\s\[(\S*)\]\s\[(\w\d{6})\]\s(\S*)\.(\w*):\s(.*)[\s|\s\[]({.*})/m'; $str = 'Feb 5 23:30:09 netoapi-06ae0d2a778f6d96c neto-ecommerce[21749]: [Self=1-5c5a1c7f-1417875ef90160804e31a159;Root=1-5c5a1c78-c849bf9b2a5aa92ee1ffd501] [N015185] app.ERROR: Entity of type \'Neto\\ShopBundle\\Entity\\Country\' for IDs code() was not found [] {""tags"":[""sales_channels""]}" Feb 5 23:10:00 cpanel-0b75ea0f831a1a35a neto-ecommerce[4987]: [Self=1-5c5a17c8-1b0a7d58cd923b42ff5a7412;Root=1-5c5a17c8-5432af944896f7d093992b3a] [N008907] app.ERROR: Uncaught PHP Exception Symfony\\Component\\HttpKernel\\Exception\\AccessDeniedHttpException: ""Installation wizard is not supported for Amazon AU"" at /opt/release/Neto6.38.0/vendor/php/symfony/symfony/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php line 117 {""exception"":""[object] (Symfony\\\\Component\\\\HttpKernel\\\\Exception\\\\AccessDeniedHttpException(code: 0): Installation wizard is not supported for Amazon AU at /opt/release/Neto6.38.0/vendor/php/symfony/symfony/src/Symfony/Component/Security/Http/Firewall/ExceptionListener.php:117, Symfony\\\\Component\\\\Security\\\\Core\\\\Exception\\\\AccessDeniedException(code: 403): Installation wizard is not supported for Amazon AU at /opt/release/Neto6.38.0/vendor/php/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/ControllerTrait.php:379)""} {""tags"":[""sales_channels""]}" Feb 5 21:35:06 netoapi-050acc5cb696746e7 neto-ecommerce[31278]: [Self=1-5c5a0188-c0db1f2809ade66c634f9576;Root=1-5c5a0185-b02bf3209835c7a4df7e5c2c] [N015185] app.ERROR: Entity of type \'Neto\\ShopBundle\\Entity\\Country\' for IDs code() was not found [] {""tags"":[""sales_channels""]}" Feb 6 05:59:30 netoapi-07743f4e14561df22 neto-ecommerce[5407]: [Self=1-5c5a77c1-0019eb7067e6cc30180f9770;Root=1-5c5a77a7-2fa7f778122a1698c2a7e286] [N016687] app.CRITICAL: Uncaught PHP Exception Doctrine\\DBAL\\Exception\\DriverException: "An exception occured in driver: SQLSTATE[HY000] [1203] User N016687_web already has more than \'max_user_connections\' active connections" at /opt/release/Neto6.38.0/vendor/php/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php line 115 {"exception":"[object] (Doctrine\\\\DBAL\\\\Exception\\\\DriverException(code: 0): An exception occured in driver: SQLSTATE[HY000] [1203] User N016687_web already has more than \'max_user_connections\' active connections at /opt/release/Neto6.38.0/vendor/php/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:115, Doctrine\\\\DBAL\\\\Driver\\\\PDOException(code: 1203): SQLSTATE[HY000] [1203] User N016687_web already has more than \'max_user_connections\' active connections at /opt/release/Neto6.38.0/vendor/php/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:47, PDOException(code: 1203): SQLSTATE[HY000] [1203] User N016687_web already has more than \'max_user_connections\' active connections at /opt/release/Neto6.38.0/vendor/php/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:43)"} {"tags":["sales_channels"]}'; 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