Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • Update Regex
    ctrl+⇧+s
  • Save new 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
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

package main import ( "regexp" "fmt" ) func main() { var re = regexp.MustCompile(`(?m),"(?<date>\d\d\d\d-\d\d-\d\d)\ (?<time>\d\d:\d\d:\d\d).*\[(?<jail>sshd|recidive|mysqld-auth)\]\ (?<action>[a-zA-z]*)\ (?<ip_address>[\d\.]*)`) var str = `@timestamp,@message 2021-04-30 18:17:08.504,"2021-04-30 19:17:04,189 fail2ban.filter [100432]: INFO [sshd] Found 221.181.185.223 - 2021-04-30 19:17:03" 2021-04-30 18:11:24.504,"2021-04-30 19:11:20,137 fail2ban.filter [100432]: INFO [sshd] Found 221.181.185.198 - 2021-04-30 19:11:19" 2021-04-30 18:04:24.504,"2021-04-30 19:04:19,434 fail2ban.filter [100432]: INFO [sshd] Found 221.131.165.56 - 2021-04-30 19:04:19" 2021-04-30 18:03:04.504,"2021-04-30 19:02:59,705 fail2ban.filter [100432]: INFO [sshd] Found 213.171.212.141 - 2021-04-30 19:02:59" 2021-04-30 17:58:11.504,"2021-04-30 18:58:06,901 fail2ban.filter [100432]: INFO [recidive] Found 205.185.119.236 - 2021-04-30 18:58:06" 2021-04-30 17:58:07.132,"2021-04-30 18:58:06,628 fail2ban.actions [100432]: NOTICE [sshd] Ban 205.185.119.236" 2021-04-30 17:58:06.631,"2021-04-30 18:58:06,208 fail2ban.filter [100432]: INFO [sshd] Found 205.185.119.236 - 2021-04-30 18:58:05" 2021-04-30 17:58:06.381,"2021-04-30 18:58:06,206 fail2ban.filter [100432]: INFO [sshd] Found 205.185.119.236 - 2021-04-30 18:58:05" 2021-04-30 17:58:06.381,"2021-04-30 18:58:06,206 fail2ban.filter [100432]: INFO [sshd] Found 205.185.119.236 - 2021-04-30 18:58:05" 2021-04-30 17:58:06.381,"2021-04-30 18:58:06,207 fail2ban.filter [100432]: INFO [sshd] Found 205.185.119.236 - 2021-04-30 18:58:05" 2021-04-30 17:58:06.381,"2021-04-30 18:58:06,207 fail2ban.filter [100432]: INFO [sshd] Found 205.185.119.236 - 2021-04-30 18:58:05" 2021-04-30 17:58:06.380,"2021-04-30 18:58:06,205 fail2ban.filter [100432]: INFO [sshd] Found 205.185.119.236 - 2021-04-30 18:58:05" 2021-04-30 17:57:40.504,"2021-04-30 18:57:35,482 fail2ban.filter [100432]: INFO [sshd] Found 221.181.185.143 - 2021-04-30 18:57:35" 2021-04-30 17:41:27.504,"2021-04-30 18:41:23,069 fail2ban.filter [100432]: INFO [sshd] Found 221.181.185.135 - 2021-04-30 18:41:22" 2021-04-30 17:40:09.504,"2021-04-30 18:40:05,206 fail2ban.filter [100432]: INFO [sshd] Found 222.187.239.107 - 2021-04-30 18:40:04" 2021-04-30 17:38:16.504,"2021-04-30 18:38:11,847 fail2ban.filter [100432]: INFO [sshd] Found 221.181.185.151 - 2021-04-30 18:38:11"` for i, match := range re.FindAllString(str, -1) { fmt.Println(match, "found at index", i) } }

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 Golang, please visit: https://golang.org/pkg/regexp/