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

`
`
mg

Test String

Code Generator

Generated Code

package main import ( "regexp" "fmt" ) func main() { var re = regexp.MustCompile(`(?m)^(?P<call>.+)>(?P<dest>.+),(?P<q>q.{2}),(?P<via>.+):@(?P<time>.+z)(?P<place>.+)_(?P<wdir>.{3})/(?P<wspd>.{3})g(?P<guts>.{3})t(?P<temp>.{3})r(?P<rain1>.{3})p(?P<rain24>.{3})P(?P<rainMn>.{3})(h(?P<hum>.{2})b(?P<press>.{5})|b(?P<press1>.{5})h(?P<hum1>.{2})).(?P<add>.+)$`) var str = `FW4018>APRS,TCPXX*,qAX,CWOP-6:@130940z4503.87N/03856.27E_005/001g004t030r000p000P000b10294h97.weewx-3.8.0-WS1 NR6G-5>APRS,NR6G-4,WIDE1*,qAR,KI6PIO-7:@140933z3517.33N/11851.40W_117/002g007t054r000p000P000h43b10263.DsVP VE3GOP>APRS,TCPIP*,qAC,T2NALA:@084045z4333.72N/07945.94W_32767/255g000t...r000p001P000h69b10260wDvs DM2KB-13>APMI01-13,TCPIP*,qAS,DM2KB:@140940z5137.03N/00704.59E_154/002g007t052r000p001P001h83b10281L241WX3in1 & Davis Vantage Pro2 WB2JSH>APRS,TCPIP*,qAC,EIGHTH:@140940z4032.40N/10447.03W_036/000g...t023r...p...P000h86b10289L000.DsVP SR8WXD>AKLPRZ,TCPIP*,qAC,T2KRAKOW:!4934.33N/02139.07E_323/011g019t032r...p...P...b..... W4VA-10>APDW15,WIDE1-1,WIDE2-1,qAR,KG4GIY:!3844.04NR07750.16W&PHG3660Viewtree Mtn, Warrenton, VA FM18br` 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/