Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
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
  • 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
Processing...

Test String

Substitution
Processing...

Code Generator

Generated Code

re = /^([0-9.]+)\s(.)\s(.)\s\[(.*)\s(\+[0-9]*)\]\s\"GET|POST\"/mi str = '127.0.0.1 - - [11/Sep/2015:08:15:33 +0600] "GET / HTTP/1.1" 200 4189 127.0.0.1 - - [11/Sep/2015:08:15:33 +0600] "GET /icons/blank.gif HTTP/1.1" 200 148 127.0.0.1 - - [11/Sep/2015:08:15:33 +0600] "GET /icons/folder.gif HTTP/1.1" 200 225 127.0.0.1 - - [11/Sep/2015:08:15:33 +0600] "GET /icons/text.gif HTTP/1.1" 200 229 127.0.0.1 - - [11/Sep/2015:08:15:33 +0600] "GET /icons/unknown.gif HTTP/1.1" 200 245 127.0.0.1 - - [11/Sep/2015:08:15:33 +0600] "GET /favicon.ico HTTP/1.1" 404 1207 127.0.0.1 - - [11/Sep/2015:08:15:40 +0600] "GET /public/ HTTP/1.1" 200 1023 127.0.0.1 - - [11/Sep/2015:08:15:37 +0600] "GET /public/ HTTP/1.1" 200 1023 127.0.0.1 - - [08/Dec/2015:11:22:28 +0600] "GET /public/index.php HTTP/1.1" 200 1023 127.0.0.1 - - [08/Dec/2015:11:22:31 +0600] "GET /favicon.ico HTTP/1.1" 404 1239 127.0.0.1 - - [08/Dec/2015:11:22:34 +0600] "GET / HTTP/1.1" 200 4189 127.0.0.1 - - [08/Dec/2015:11:22:34 +0600] "GET /icons/blank.gif HTTP/1.1" 200 148 127.0.0.1 - - [08/Dec/2015:11:22:34 +0600] "GET /icons/folder.gif HTTP/1.1" 200 225 127.0.0.1 - - [08/Dec/2015:11:22:34 +0600] "GET /icons/unknown.gif HTTP/1.1" 200 245 127.0.0.1 - - [08/Dec/2015:11:22:34 +0600] "GET /icons/text.gif HTTP/1.1" 200 229 127.0.0.1 - - [08/Dec/2015:11:22:52 +0600] "GET / HTTP/1.1" 200 1023 127.0.0.1 - - [08/Dec/2015:11:23:05 +0600] "GET / HTTP/1.1" 200 1023 127.0.0.1 - - [08/Dec/2015:11:23:07 +0600] "GET /public/index.php HTTP/1.1" 404 16638 127.0.0.1 - - [08/Dec/2015:11:23:12 +0600] "GET / HTTP/1.1" 200 1023 127.0.0.1 - - [08/Dec/2015:11:23:40 +0600] "GET /auth/ HTTP/1.1" 301 332 127.0.0.1 - - [08/Dec/2015:11:23:40 +0600] "GET /auth HTTP/1.1" 404 16638 127.0.0.1 - - [08/Dec/2015:11:23:45 +0600] "GET /auth/login HTTP/1.1" 404 16638 127.0.0.1 - - [08/Dec/2015:11:23:49 +0600] "GET / HTTP/1.1" 200 1023 127.0.0.1 - - [08/Dec/2015:11:44:02 +0600] "GET / HTTP/1.1" 200 1046 127.0.0.1 - - [08/Dec/2015:12:11:53 +0600] "GET / HTTP/1.1" 200 1023 127.0.0.1 - - [29/Dec/2015:10:29:46 +0600] "GET / HTTP/1.1" 200 11160 127.0.0.1 - - [29/Dec/2015:10:29:47 +0600] "GET /_debugbar/assets/stylesheets?1451362463 HTTP/1.1" 200 196851 127.0.0.1 - - [29/Dec/2015:10:29:47 +0600] "GET /_debugbar/assets/javascript?1451362459 HTTP/1.1" 200 348784 127.0.0.1 - - [29/Dec/2015:10:29:48 +0600] "GET /favicon.ico HTTP/1.1" 200 - 127.0.0.1 - - [29/Dec/2015:10:30:58 +0600] "GET /auth HTTP/1.1" 404 29966 127.0.0.1 - - [29/Dec/2015:10:32:24 +0600] "GET /_debugbar/open?max=20&offset=0 HTTP/1.1" 200 289 127.0.0.1 - - [29/Dec/2015:11:08:46 +0600] "GET /auth/register HTTP/1.1" 404 28750 127.0.0.1 - - [30/Dec/2015:08:43:01 +0600] "GET /auth/register HTTP/1.1" 404 27092 127.0.0.1 - - [30/Dec/2015:08:43:14 +0600] "GET /_debugbar/assets/stylesheets?1451362463 HTTP/1.1" 200 196851 127.0.0.1 - - [30/Dec/2015:08:43:14 +0600] "GET /_debugbar/assets/javascript?1451362459 HTTP/1.1" 200 348784 127.0.0.1 - - [30/Dec/2015:08:43:15 +0600] "GET /favicon.ico HTTP/1.1" 200 - 127.0.0.1 - - [30/Dec/2015:11:51:32 +0600] "GET / HTTP/1.1" 200 9902 127.0.0.1 - - [30/Dec/2015:11:51:34 +0600] "GET /favicon.ico HTTP/1.1" 200 - 127.0.0.1 - - [30/Dec/2015:12:22:13 +0600] "GET /auth HTTP/1.1" 404 28622 127.0.0.1 - - [28/Mar/2016:12:32:18 +0600] "GET / HTTP/1.1" 200 9881 127.0.0.1 - - [28/Mar/2016:12:32:38 +0600] "GET /_debugbar/assets/stylesheets?1451362463 HTTP/1.1" 200 196851 127.0.0.1 - - [28/Mar/2016:12:32:38 +0600] "GET /_debugbar/assets/javascript?1451362459 HTTP/1.1" 200 348784 127.0.0.1 - - [28/Mar/2016:12:32:39 +0600] "GET /favicon.ico HTTP/1.1" 200 - ' subst = '' result = str.gsub(re, subst) # Print the result of the substitution puts 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 Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html