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 = '/v\d+\.\d+\.\d+\.\d+/m'; $str = '36168f5d0262a3c77be966f669483b6dd4b5feb2 refs/tags/v22.10.11.3-develop 35b11636ca48fe4033a6fe8fb023a78094f4536b refs/tags/v22.10.11.2-develop 5e3065a75fbc2a2a7f81ffc63e432d5ce6f482c3 refs/tags/v22.10.11.1-develop 3709d86fd22276ea784ff3a1bb9351ffec737d98 refs/tags/v22.10.10.7-develop 33d06475ba7a2ab8dafb6eb439edb742a118018e refs/tags/v22.10.10.6-develop de839ee4d535400aaaa7ea2e26d7db144d60aa8a refs/tags/v22.10.10.5-develop f44477b63cb260dad79de11a99aa1888ecedeaeb refs/tags/v22.10.10.4-develop 2d53acd352bee485ea372fb6f3f5415b1bb65bd8 refs/tags/v22.10.10.3-develop 472f146bf38a8d5db232468fee8c31ab4fe6075d refs/tags/v22.10.10.2-develop bb58575af76849f965962b29ed6bc19022df8783 refs/tags/v22.10.10.1-develop c5f5cb120b31e646dcdfe1a3507a47f06db4fca0 refs/tags/v22.10.10.0-develop 2b4d8d78e942c9b4a5a089a814a5ec510618403d refs/tags/v22.10.07.25-develop 0c8eeb9d0edf759fcb18f52376f423b4aa709d83 refs/tags/v22.10.07.24-develop 6d8e520cc0aaf7cea4d3d0f7b9c2d2c772dea055 refs/tags/v22.10.07.23-develop f9299af9b12b03a672fcddf2acfd1e9072a96f60 refs/tags/v22.10.07.22-develop d73625323be39a21c55d62f46906d723d172f154 refs/tags/v22.10.07.21-develop d2e912c62f665e29715de76ecb715266a7c66816 refs/tags/v22.10.07.20-develop 5c2cfd165b09c0278d0a3b0ec60874c77220a5e1 refs/tags/v22.10.07.19-develop 23747bc01c1124573fa761c5ae88b6833c6c4cab refs/tags/v22.10.07.18-develop b7686f423c5bda9b6b77bd4555bcd7ef3f4b741e refs/tags/v22.10.07.17-develop 31e748884454f60ab9f77912f222a96b0862ba99 refs/tags/v22.10.07.16-develop 34f063a1e498d15296931342769009e3ace66088 refs/tags/v22.10.07.15-develop aad1b0422f6f71211d2c66e97c5e88666d923427 refs/tags/v22.10.07.14-develop 47eedc45801d869865135fb804ed9c7d68be8924 refs/tags/v22.10.07.13-develop 4299f668eef4254d284ef0f6af14bf3059404477 refs/tags/v22.10.07.12-develop 65c7f411f5c84ab605c299bbf42dcdaa043af57a refs/tags/v22.10.07.11-develop be70c9ee78e0667ef897918c6cacde7c4d3a3048 refs/tags/v22.10.07.10-develop b124ab9df7c5fb5e9298c1501fc1b50ebfb9830f refs/tags/v22.10.07.9-develop 4a9eaa4b188167b39200a0a209f70e856211e89b refs/tags/v22.10.07.8-develop b9327b8a0fe846c7f9ee49125d95d2deb73c330c refs/tags/v22.10.07.7-develop 0b648d33875b7f7b3fd1be682caadcff1a55a61d refs/tags/v22.10.07.6-develop 74b3f187a9993d23456cfd3983233076c3e8750f refs/tags/v22.10.07.5-develop 9f318497675d30b5ac861f6f5040931fb77a7257 refs/tags/v22.10.07.4-develop 22a5935f8eedb97cdbacdb28e8b577f788852dc4 refs/tags/v22.10.07.3-develop 99939991e697f494a6328e737f411f51be75dd0f refs/tags/v22.10.07.2-develop 2660d0b7a243e025a9f8ed70b626cb83b31d5885 refs/tags/v22.10.07.1-develop 4b8489596cbe0f2e8d799f8c51214628970cafe1 refs/tags/v22.10.07.0-develop b35987cc837d8df98f8dd412dda1cf92c7c05682 refs/tags/v22.10.05.4-develop 9b56abb6e2957be12e2f76c120de7a3a033d84c4 refs/tags/v22.10.05.3-develop 8ab916b32be1b6aceb9284cb8f2c3a62083babb7 refs/tags/v22.10.05.2-develop c428874e61a15381f9357f0594a7a2da7ddb9e74 refs/tags/v22.10.05.1-develop 1ec1ce52c92023c4d52aad2eac6350feed563b9c refs/tags/v22.10.05.0-develop '; 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