Regular Expressions 101

Save & Share

  • Save new Regex
    ctrl+s
  • Update 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
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

/
/
gm

Test String

Code Generator

Generated Code

$re = '/^(?<vendor_date>\d{4}(?:\-\d\d){2} [^,]+,[^:]+):(?<vendor_level>[^:]+):(?<vendor_component>[^:]+):(?<vendor_message>[^\n\r]+)(?<vendor_details>(?(?=^\d{4}(?:\-\d\d){2})|[^\r])+)?/m'; $str = '2019-10-14 11:07:08,727:DEBUG:certbot.cli:Var dry_run=True (set by user). 2019-10-14 11:07:08,727:DEBUG:certbot.cli:Var server={\'dry_run\', \'staging\'} (set by user). 2019-10-14 11:07:08,727:DEBUG:certbot.cli:Var dry_run=True (set by user). 2019-10-14 11:07:08,728:DEBUG:certbot.cli:Var server={\'dry_run\', \'staging\'} (set by user). 2019-10-14 11:07:08,728:DEBUG:certbot.cli:Var account={\'server\'} (set by user). 2019-10-14 11:07:08,757:INFO:certbot.renewal:Cert not due for renewal, but simulating renewal for dry run 2019-10-14 11:07:08,757:DEBUG:certbot.plugins.selection:Requested authenticator nginx and installer nginx 2019-10-14 11:07:10,881:DEBUG:certbot.plugins.selection:Single candidate plugin: * nginx Description: Nginx Web Server plugin Interfaces: IAuthenticator, IInstaller, IPlugin Entry point: nginx = certbot_nginx.configurator:NginxConfigurator Initialized: Prep: True 2019-10-14 11:07:10,888:DEBUG:certbot.plugins.selection:Single candidate plugin: * nginx Description: Nginx Web Server plugin Interfaces: IAuthenticator, IInstaller, IPlugin Entry point: nginx = certbot_nginx.configurator:NginxConfigurator Initialized: Prep: True 2019-10-14 11:07:10,889:DEBUG:certbot.plugins.selection:Selected authenticator and installer 2019-10-14 11:07:10,889:INFO:certbot.plugins.selection:Plugins selected: Authenticator nginx, Installer nginx 2019-10-14 11:07:10,902:DEBUG:certbot.main:Picked account: )>), only_return_existing=None, contact=(\'mailto:trol@yopmail.com\',), agreement=\'https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf\')), 019763ae9d0030f2ffa8f8cb689e7976, Meta(creation_dt=datetime.datetime(2018, 2, 27, 14, 17, 55, tzinfo=), creation_host=\'sd-99715.dedibox.fr\'))> 2019-10-14 11:07:10,911:DEBUG:acme.client:Sending GET request to https://acme-staging-v02.api.letsencrypt.org/directory. 2019-10-14 11:07:10,998:DEBUG:requests.packages.urllib3.connectionpool:Starting new HTTPS connection (1): acme-staging-v02.api.letsencrypt.org 2019-10-14 11:07:14,617:DEBUG:requests.packages.urllib3.connectionpool:https://acme-staging-v02.api.letsencrypt.org:443 "GET /directory HTTP/1.1" 200 724 2019-10-14 11:07:14,619:DEBUG:acme.client:Received response: HTTP 200 Server: nginx Date: Mon, 14 Oct 2019 09:07:14 GMT Content-Type: application/json Content-Length: 724 Connection: keep-alive Cache-Control: public, max-age=0, no-cache X-Frame-Options: DENY Strict-Transport-Security: max-age=604800 { "kRr68eKT_x4": "https://community.letsencrypt.org/t/adding-random-entries-to-the-directory/33417", "keyChange": "https://acme-staging-v02.api.letsencrypt.org/acme/key-change", "meta": { "caaIdentities": [ "letsencrypt.org" ], "termsOfService": "https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf", "website": "https://letsencrypt.org/docs/staging-environment/" }, "newAccount": "https://acme-staging-v02.api.letsencrypt.org/acme/new-acct", "newNonce": "https://acme-staging-v02.api.letsencrypt.org/acme/new-nonce", "newOrder": "https://acme-staging-v02.api.letsencrypt.org/acme/new-order", "revokeCert": "https://acme-staging-v02.api.letsencrypt.org/acme/revoke-cert" } 2019-10-14 11:07:14,620:INFO:certbot.main:Renewing an existing certificate 2019-10-14 11:07:14,999:DEBUG:acme.client:Requesting fresh nonce 2019-10-14 11:07:15,006:DEBUG:acme.client:Sending HEAD request to https://acme-staging-v02.api.letsencrypt.org/acme/new-nonce. 2019-10-14 11:07:15,156:DEBUG:requests.packages.urllib3.connectionpool:https://acme-staging-v02.api.letsencrypt.org:443 "HEAD /acme/new-nonce HTTP/1.1" 200 0 2019-10-14 11:07:15,158:DEBUG:acme.client:Received response: HTTP 200 Server: nginx Date: Mon, 14 Oct 2019 09:07:15 GMT Connection: keep-alive Cache-Control: public, max-age=0, no-cache Link: https://acme-staging-v02.api.letsencrypt.org/directory;rel="index" Replay-Nonce: 0002fqXrdxZwV_xxxxx-xxxxxxxx-KdWhvOCtgFh5YNNVM X-Frame-Options: DENY Strict-Transport-Security: max-age=604800 2019-10-14 11:07:15,158:DEBUG:acme.client:Storing nonce: 0002fqXrdxZwV_xxxxx-xxxxxxxx-KdWhvOCtgFh5YNNVM 2019-10-14 11:07:15,160:DEBUG:acme.client:JWS payload: b\'{\\n "identifiers": [\\n {\\n "type": "dns",\\n "value": "site.tld"\\n },\\n {\\n "type": "dns",\\n "value": "cdn-css. site.tld "\\n },\\n {\\n "type": "dns",\\n "value": "cdn-js-body. site.tld "\\n },\\n {\\n "type": "dns",\\n "value": "cdn-js-footer. site.tld "\\n },\\n {\\n "type": "dns",\\n "value": "cdn-js-head. site.tld "\\n },\\n {\\n "type": "dns",\\n "value": "www. site.tld "\\n }\\n ]\\n}\' 2019-10-14 11:07:15,173:DEBUG:acme.client:Sending POST request to https://acme-staging-v02.api.letsencrypt.org/acme/new-order: { "protected": "SOmeBASE64Str", "payload": "ANOTHERB64STR", "signature": "YETANOTHERB64STR" } 2019-10-14 11:07:15,387:DEBUG:requests.packages.urllib3.connectionpool:https://acme-staging-v02.api.letsencrypt.org:443 "POST /acme/new-order HTTP/1.1" 201 1104'; 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