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
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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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

/
/
smg

Test String

Substitution

Processing...

Code Generator

Generated Code

$re = '/^(\S*)\s+([\-\+])\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/sm'; $str = 'BER_333_10173 - 72 812 1372 2180 2250 87 BER_333_10173 + 72 812 1372 2180 2250 88 BER_333_10173 + 72 812 1372 2180 2250 92 BER_333_10173 - 72 812 1372 2180 2250 93 633310098 + 69,7 909,7 1619,8 2379,8 2430 111 633310098 - 69,8 909,8 1619,8 2379,8 2430 110 633310098 - 69,7 909,7 1619,8 2379,8 2430 97 633310098 + 69,8 909,8 1619,8 2379,8 2430 96 633310099 - 71,11 662,02 1343,05 2050 2100 55 633310099 + 71,11 662,01 1343,08 2050 2100 56 633310099 + 71,11 662,02 1343,05 2050 2100 59 633310099 - 71,11 662,01 1343,08 2050 2100 60 633310108 - 68,7 716 1461 2249 2299 112 633310108 + 68,7 716 1461 2249 2299 113 BER_333_10176 - 153,5 843,5 1503,5 2278,5 2430 119 BER_333_10176 + 153,5 843,5 1503,5 2278,5 2430 120 BER_333_10195 - 72,55 522,53 1172,51 1722,55 1875 63 BER_333_10195 + 72,55 522,53 1172,51 1722,55 1875 64 BER_333_10195 + 72,55 522,53 1172,51 1722,55 1875 61 BER_333_10195 - 72,55 522,53 1172,51 1722,55 1875 62 BER_333_10175 - 99,8 939,8 1899,8 0 1980 125 BER_333_10175 + 99,8 939,8 1899,8 0 1980 126 BER_333_10175 + 99,8 939,8 1899,8 0 1980 123 BER_333_10175 - 99,8 939,8 1899,8 0 1980 124 BER_333_10197 - 62 716 1249 1949 1999 121 BER_333_10197 + 62 716 1249 1949 1999 122 BER_333_10193 - 72,46 522,47 1172,41 1722,43 1875 65 BER_333_10193 + 72,43 522,44 1172,41 1722,43 1875 66 '; $subst = ";$1\nLBL $8\nQ10 = $2 $7 ; Longueur entretoises\nQ11 = $2 $3 ; TROU 1\nQ12 = $2 $4 ; TROU 2\nQ13 = $2 $5 ; TROU 3\nQ14 = $2 $6 ; TROU 4\nCALL LBL 1"; $result = preg_replace($re, $subst, $str); echo "The result of the substitution is ".$result;

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