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
No Match

`
`
gm

Test String

Code Generator

Generated Code

package main import ( "regexp" "fmt" ) func main() { var re = regexp.MustCompile(`(?m)(?m)^NAME="(?P<name>(?P<disk>[a-z]+)(?P<partition>\d*))"\sFSTYPE="(?P<fstype>\w*)"\sMOUNTPOINT="(?P<mountpoint>[\w\[\]/]*)"\sSIZE="(?P<size>\d*)"\sTYPE="(?P<type>\w+)"$`) var str = `NAME="loop0" FSTYPE="LVM2_member" MOUNTPOINT="" SIZE="20971520000" TYPE="loop" NAME="sda" FSTYPE="" MOUNTPOINT="" SIZE="171798691840" TYPE="disk" NAME="sda1" FSTYPE="ext4" MOUNTPOINT="/boot" SIZE="1073741824" TYPE="part" NAME="sda2" FSTYPE="LVM2_member" MOUNTPOINT="" SIZE="170723901440" TYPE="part" NAME="sdb" FSTYPE="" MOUNTPOINT="" SIZE="32212254720" TYPE="disk" NAME="sdb1" FSTYPE="LVM2_member" MOUNTPOINT="" SIZE="32211206144" TYPE="part" NAME="sdc" FSTYPE="" MOUNTPOINT="" SIZE="53687091200" TYPE="disk" NAME="sdc1" FSTYPE="LVM2_member" MOUNTPOINT="" SIZE="53686042624" TYPE="part" NAME="sr0" FSTYPE="" MOUNTPOINT="" SIZE="1073741312" TYPE="rom" NAME="cl_ctos8auto-root" FSTYPE="xfs" MOUNTPOINT="/" SIZE="106300440576" TYPE="lvm" NAME="cl_ctos8auto-root" FSTYPE="xfs" MOUNTPOINT="/" SIZE="106300440576" TYPE="lvm" NAME="cl_ctos8auto-swap" FSTYPE="swap" MOUNTPOINT="[SWAP]" SIZE="8497659904" TYPE="lvm" NAME="cl_ctos8auto-home" FSTYPE="xfs" MOUNTPOINT="/home" SIZE="108536004608" TYPE="lvm" NAME="cl_ctos8auto-var_log" FSTYPE="ext4" MOUNTPOINT="/opt/imsdb/chroot-sybase/var/log" SIZE="32208060416" TYPE="lvm" NAME="b38ad718--fc07--11ea--9894--0050569ae644-fea1a18c--fc07--11ea--9894--0050569ae644" FSTYPE="ext4" MOUNTPOINT="/opt/intelerad/atlas/1/storage/b30f29df-8fc2-4db5-8c17-4275cdae6b3f" SIZE="20967325696" TYPE="lvm"` 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/