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"
"
gims

Test String

Code Generator

Generated Code

package main import ( "regexp" "fmt" ) func main() { var re = regexp.MustCompile(`(?ims)(?:CRITERION SUMMARY.*?\n)(.*?)(?:\n{2}|\.PLOT PAGE)`) var str = ` Fr. 180 135.000f -1,320.8 45 -2,911.4 8,472.3 27 31,259.0 Fr. 184 138.000f -1,032.5 44 -2,367.4 4,966.8 20 25,416.1 Fr. 189 141.750f -689.6 41 -1,687.4 1,530.8 8 18,112.6 FPP 143.250f -421.6 30 -1,415.4 697.3 5 15,191.2 ------------------------------------------------------------------------------ LONG. STRENGTH - PORT CONDITION CRITERION SUMMARY Largest Shear/limit: 47.3% at 140.000f Largest Bending Moment/limit: 32.4% at 130.572f (Hogging) Largest Shear: 2,094.1 MT at 120.000f Largest Bending Moment: -42,063 MT-m. at 76.500f (Sagging) .PLOT PAGE D&T=19-11-15 11:25:20 PAG= 398 P&V=GHS 14.62B TIT=Vuyk Engineering Rotterdam B.V. TIT=MV FJELL - IMO 8766296 HDG=6.09 - BALLASTING - STEP 9\ HDG=DAMAGE CONDITION\ CAT= DAM= with FLOODING UNT=M. MT CU.M. ORV=Base plane SPG= 1.025 STD WAV= 0 LIM=LONG. STRENGTH - PORT CONDITION HEL= 4.848391 LST= 375 LOC SHR SLN SLP MOM MLN MLP -148 0 -554 378 0 5940 -3994 -148 0 -554 378 0 5940 -3994 -147.07 -1.110508 -722.6383 556.4048 1.96067 7751.208 -5850.188 -147.07 -1.110508 -722.6484 556.4155 1.96067 7751.316 -5850.3 -146.9999 -6.46569 -735.3599 569.8632 2.33537 7887.84 -5990.214 -146.9999 -6.46569 -735.37 569.8739 2.33537 7887.949 -5990.325 -146.9968 -6.697881 -735.9165 570.452 2.360113 7893.819 -5996.341 -146.4246 -53.68822 -839.6799 680.2248 20.21089 9008.258 -7138.457 -146.4246 -53.68822 -839.69 680.2355 20.21089 9008.366 -7138.568 -146.25 -69.215 -871.3339 713.712 31.2016 9348.228 -7486.869 ` 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/