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

r"
"
gm

Test String

Code Generator

Generated Code

package main import ( "regexp" "fmt" ) func main() { var re = regexp.MustCompile(`(?m)^(?P<unit_type>CD|CG|CS)(?P<series>M1)(?P<mounting_type>MP5|MF4|MT4|MF3|MP3|MF2|MS2|MF1|M00)(?P<sep_1>/)(?P<piston>200|160|125|100|80|63|50|40|32|25|)(?P<sep_2>/)(?P<piston_rod>140|110|90|70|56|45|36|28|22|18|14)(?P<sep_3>/)(?P<stroke_length>[\d.]{4})(?P<design_principle>A)(?P<unit_series>2X)(?P<sep_4>/)(?P<pipe_port>B|R|S|F|H|P|T|U|A|E|L)(?P<position_head>4|3|2|1|)(?P<position_base>4|3|2|1|.)(?P<piston_rod_design>H|C|L)(?P<piston_rod_end>G|H|E|F|K)(?P<position_cushioning>U|D|S|K|E|N)(?P<seal_material>M|T|A|V|S)(?P<proximity_switche>W|A|E|T)(?P<piston_rod_extension>W|Y|C|F|D|)$`) var str = `CDM1MT4/100/56/.360A2X/B1.CGDMWW CDM1MT4/40/22/.225A2X/B1.CGDMWW CDM1MT4/50/36/..80A2X/B1.CHDMWW CDM1MT4/32/18/.225A2X/B1.CGDMWW CDM1MT4/80/45/.550A2X/B1.CGDMWW CDM1MT4/125/90/1100A2X/B11CGDMW CDM1MT4/25/14/.130A2X/B11CGDMW CDM1MT4/40/22/.450A2X/B11CGDMW CDM1MT4/63/36/.290A2X/B11CGDVW CDM1MT4/50/28/..55A2X/B11CGDMW CDM1MT4/100/56/.250A2X/B11CGDMW CDM1MS2/100/70/.160A2X/B33CHDMW CDM1MT4/50/28/.700A2X/B11CGDVW CDM1MT4/50/36/..50A2X/B11CGDMW CDM1MT4/50/28/.700A2X/B11CGDVW CDM1MT4/40/28/.480A2X/B11CGDVW CSM1MT4/63/45/1000A2X/B22CGUMTCXV250 CDM1MF1/100/56/..80A2X/B11CGDMWW CDM1MT4/25/18/.320A2X/B11CGDMWW CDM1MT4/40/28/.200A2X/B11CHDMWW CDM1MT4/40/22/..90A2X/B11CGDMWW CDM1MT4/25/14/..70A2X/B11CGDMWW CDM1MF3/32/22/.360A2X/B11CGDMWW CYM1MF1/32/22/.300A20/B11CXDMS37796 ` 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/