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

/
/
g

Test String

Code Generator

Generated Code

$re = '/(commit [0-9a-f]{40})(\sMerge:\s[0-9a-f]{7}\s[0-9a-f]{7})?\sAuthor:\s(\w*)\sDate:\s[a-zA-Z]{3}\s[a-zA-z]{3}\s\d\d\s\d\d:\d\d:\d\d\s[\d]{4}\s\+0200\s+(?<message>(?:(?!commit .{40}).)+)/'; $str = 'commit 896a5d608a53ae67293eb7ba04c40abc271cfe79 Merge: bbf7582 d4e921d Author: stage Date: Wed Aug 31 12:51:42 2016 +0200 Merge branch \'master\' into ciaocop commit d4e921dff0fcf5a3aeee2c2cefb7adc58f44bd7a Merge: bd8912c cc4c493 Author: stage Date: Wed Aug 31 12:48:10 2016 +0200 Merge branch \'test\' commit cc4c49345b29b4994d65459fd4bb7addba78d36f Author: stage Date: Wed Aug 31 12:40:11 2016 +0200 a caso commit bd8912c97707cec7d1f48bb98e03f2324c0dd541 Merge: 6dbba13 bbf7582 Author: stage Date: Wed Aug 31 12:26:28 2016 +0200 Merge branch \'master\' into temp commit bbf7582f71d3c1de836cf12971c7dda5b4fab75b Author: stage Date: Wed Aug 31 12:13:11 2016 +0200 ciao cop commit aa8dd5307a5b6d1622ba200758f9558a50fc21b1 Merge: 6dbba13 c2e08ac Author: stage Date: Wed Aug 31 11:50:07 2016 +0200 Merge branch \'master\' into temp commit c2e08acb9bec648eac5b6b129d893bcf44495faf Merge: 6dbba13 7e87c99 Author: stage Date: Wed Aug 31 11:47:34 2016 +0200 Merge branch \'master\' into temp commit 7e87c99bbdc97241a7ecdf0c9635b058fcd9c7e2 Merge: 6dbba13 312a29c Author: stage Date: Wed Aug 31 11:45:20 2016 +0200 Merge branch \'master\' into temp commit 312a29cad43412481b277248bc2d4f2d569db69e Author: stage Date: Wed Aug 31 11:13:49 2016 +0200 nuovo file su test commit 2b64e458aba6ed6f7fa3d66690241de566a5d8db Merge: 2017540 682b494 Author: stage Date: Wed Aug 31 11:11:36 2016 +0200 Merge branch master into test commit 682b494ae3b42931370f2618a5eef504e05a8010 Merge: 2017540 17f3a45 Author: stage Date: Wed Aug 31 10:53:02 2016 +0200 Merge branch \'master\' into test commit 17f3a4506cf1de07a339c09b160430d0c51d624b Author: stage Date: Wed Aug 31 10:39:46 2016 +0200 rotto il db commit 6dbba13bbbf1884e7d5d3e468a7989aad015d876 Author: stage Date: Wed Aug 31 10:37:03 2016 +0200 dopo tema attivato commit 2017540a55992a9e48b8c65c0595dae0b7535f97 Author: stage Date: Wed Aug 31 10:15:29 2016 +0200 netkom: Tema attivato commit 6f5d281158f7afa706b2e475c6a3073d5d36f193 Author: stage Date: Wed Aug 31 10:12:12 2016 +0200 coptest_stage : empty initial commit'; 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