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

/
/
gm

Test String

Substitution

Processing...

Code Generator

Generated Code

package main import ( "regexp" "fmt" ) func main() { var re = regexp.MustCompile(`(?m)^((.+)\.TP.+\.LS\t)(.{2,99})$`) var str = `BG_LOGIC.TP BG_LOGIC.LS BG Logic CICLO.TP CICLO.LS Ciclo carico CICLO_SIM.TP CICLO_SIM.LS Ciclo carico CLSKP_G1.TP CLSKP_G1.LS set skip cond g1 CLSKP_G2.TP CLSKP_G2.LS set skip cond g2 CLSKP_G3.TP CLSKP_G3.LS set skip cond g3 CLSKP_G4.TP CLSKP_G4.LS set skip cond g4 CLSKP_G5.TP CLSKP_G5.LS set skip cond g5 CLSKP_G6.TP CLSKP_G6.LS set skip cond g6 CLSKP_G7.TP CLSKP_G7.LS set skip cond g7 CLSKP_G8.TP CLSKP_G8.LS set skip cond g8 CMD_TOOL.TP CMD_TOOL.LS Comandi tool CTRL_COLORE.TP CTRL_COLORE.LS Controllo colore CTRL_SMUS.TP CTRL_SMUS.LS Controllo smussi DEFINREG.TP DEFINREG.LS Defin. registri DEFINTOO.TP DEFINTOO.LS Definisci tool DEF_PR.TP DEF_PR.LS Defin. PR ciclo DEF_PR_DEMO.TP DEF_PR_DEMO.LS Defin. PR ciclo DEMO_CLC.TP DEMO_CLC.LS Cycle DEMO DEMO_OFF.TP DEMO_OFF.LS Ciclo Demo Offst DOFF_NTV.TP DOFF_NTV.LS DemoOffs no Tav DOFF_TAV.TP DOFF_TAV.LS DemoOffs con Tav GETDATA.TP GETDATA.LS Get PC Data HOME.TP HOME.LS Vai a Home HOMESCAR.TP HOMESCAR.LS Home+Scarto INIT.TP INIT.LS InitVars INIT_CICLO.TP INIT_CICLO.LS InitCiclo INIT_POS.TP INIT_POS.LS InitPosizioni LASCIA.TP LASCIA.LS Lascia pastiglia MAGNETE1.TP MAGNETE1.LS Cmd magnete A MAGNETE2.TP MAGNETE2.LS Cmd magnete B MANUT.TP MANUT.LS Manutenzione OFFSET.TP OFFSET.LS Offset da PLC OVERRIDE.TP OVERRIDE.LS Assegna Override OVER_BAS.TP OVER_BAS.LS Override ridotta OVER_LIM.TP OVER_LIM.LS BG_Logic OVER_RIP.TP OVER_RIP.LS BG_Logic POSIZIONE.TP POSIZIONE.LS COMPARATORE PREDISP_TAV.TP PREDISP_TAV.LS Piano formella PRENDI.TP PRENDI.LS Prendi pastiglia PRG_1.TP PRG_1.LS 1336 PRG_2.TP PRG_2.LS 549 Hole PRG_3.TP PRG_3.LS 201659.100 PRG_998.TP PRG_998.LS NoHole PRG_999.TP PRG_999.LS Hole PRIOR_PREL.TP PRIOR_PREL.LS Prior. prelievo PROVA.TP PROVA.LS Test PULPZ.TP PULPZ.LS Pulizia pinza REQMENU.TP REQMENU.LS Request PC Menu RISCAL.TP RISCAL.LS Riscaldamento RSR0001.TP RSR0001.LS Prog. Avvio SCARTO.TP SCARTO.LS Scarto SENDDATA.TP SENDDATA.LS Send PC Data SENDEVNT.TP SENDEVNT.LS Send PC Event SENDSYSV.TP SENDSYSV.LS Send PC SysVar SETSKCOL.TP SETSKCOL.LS setskipcondition SET_SR.TP SET_SR.LS Set string reg. TARA_COLORE.TP TARA_COLORE.LS Tara ctrl colore TEST.TP TEST.LS Temp TEST_MOV.TP TEST_MOV.LS Prova movimenti VRFYPREL.TP VRFYPREL.LS Check Prel. Nas. VRFYPRTV.TP VRFYPRTV.LS Check Prel. Tav. _MAIN.TP _MAIN.LS Prog. principale _RESET.TP _RESET.LS Carica punti ` var substitution = "PRG\t\2\t\3" fmt.Println(re.ReplaceAllString(str, substitution)) }

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/