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

~
~
xg

Test String

Code Generator

Generated Code

$re = '~\#(?P<cycle>\d+)\s (?P<date>[\d/]+)\s (?P<time>[\d:]+)\s+ Total:\s(?P<total>[\d.]+)[-\s]+ RCPE:\s+(?P<rcpe>\d+)\s ID:\s(?P<id>\d+)\s WKOD:\s+(?P<wkod>\d+)\s OPRT:\s+(?P<oprt>\d+)\s TARE:\s(?P<tare>[.\d]+)~x'; $str = '--------- #1157 11/06/2015 09:44:21 Total: 2482.3 --------- RCPE: 101 ID: 204 WKOD: 0 OPRT: 0 TARE: 13.6 MAT ADDI(2) REGR(4) ADDI(5) ADDI(6) NATU(8) 2% 25% 0.5% 1.3% 100 FINA R 1.89 25.36 0.54 1.31 100.00 FINA W 33.7 629.4 9.6 23.3 1786.1 1st DW 22.8 629.4 9.6 23.3 1786.1 1st DT 79.0 1578.0 3622.0 9753.0 8468.0 1st FR 449.37 396.19 2.47 2.38 212.82 DW/DT 288.40 398.88 2.66 2.39 210.93 FRate 449.37 396.19 2.57 2.38 211.87 Retry# 02 --------- #1158 11/06/2015 09:45:40 Total: 2513.7 --------- RCPE: 101 ID: 204 WKOD: 0 OPRT: 0 TARE: 12.4 MAT ADDI(2) REGR(4) ADDI(5) ADDI(6) NATU(8) 2% 25% 0.5% 1.3% 100 FINA R 1.81 25.48 0.49 1.28 100.00 FINA W 32.8 640.4 8.8 23.2 1808.4 1st DW 21.1 640.4 8.8 23.2 1705.8 1st DT 80.0 1578.0 3524.0 9875.0 8456.0 1st FR 449.37 396.19 2.57 2.38 211.87 DW/DT 263.20 405.85 2.51 2.35 201.73 FRate 449.37 396.19 2.57 2.38 206.80 Retry# 01 01 --------- #1159 11/06/2015 09:46:43 Total: 2484.9 --------- RCPE: 101 ID: 204 WKOD: 0 OPRT: 0 TARE: 12.3 MAT ADDI(2) REGR(4) ADDI(5) ADDI(6) NATU(8) 2% 25% 0.5% 1.3% 100 FINA R 1.83 25.36 0.51 1.26 100.00 FINA W 32.8 630.2 9.1 22.6 1790.2 1st DW 24.3 630.2 9.1 22.6 1790.2 1st DT 80.0 1578.0 3489.0 9775.0 8710.0 1st FR 449.37 396.19 2.57 2.38 206.80 DW/DT 303.24 399.39 2.60 2.31 205.53 FRate 449.37 396.19 2.57 2.38 206.80 Retry# 01 --------- #1160 11/06/2015 09:47:58 Total: 2581.8 --------- RCPE: 101 ID: 204 WKOD: 0 OPRT: 0 TARE: 12.7 MAT ADDI(2) REGR(4) ADDI(5) ADDI(6) NATU(8) 2% 25% 0.5% 1.3% 100 FINA R 1.91 25.06 0.49 1.30 100.00 FINA W 35.6 646.9 9.1 24.3 1865.9 1st DW 23.8 646.9 7.5 24.3 1865.9 1st DT 83.0 1578.0 3636.0 10188.0 8633.0 1st FR 449.37 396.19 2.57 2.38 206.80 DW/DT 287.02 409.98 2.07 2.38 216.13 FRate 449.37 396.19 2.32 2.38 211.47 Retry# 02 01 --------- #1161 11/06/2015 09:49:01 Total: 2645.1 --------- RCPE: 101 ID: 204 WKOD: 0 OPRT: 0 TARE: 12.3 MAT ADDI(2) REGR(4) ADDI(5) ADDI(6) NATU(8) 2% 25% 0.5% 1.3% 100 FINA R 1.87 24.36 0.52 1.34 100.00 FINA W 36.1 644.3 10.1 25.9 1928.8 1st DW 24.8 644.3 10.1 25.9 1928.8 1st DT 86.0 1578.0 4159.0 10532.0 8454.0 1st FR 449.37 396.19 2.32 2.38 211.47 DW/DT 288.18 408.28 2.43 2.46 228.15 FRate 449.37 396.19 2.32 2.42 219.81 Retry# 02 '; preg_match_all($re, $str, $matches, PREG_SET_ORDER, 0); // Print the entire match result var_dump($matches);

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 PHP, please visit: http://php.net/manual/en/ref.pcre.php