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

/
/
mg

Test String

Substitution

Processing...

Code Generator

Generated Code

$re = '/^.*(LIGNE|Espace|Maintien|point|Delta|ENTREE).*\n/m'; $str = 'LIGNE Calque: "506" Espace: Espace objet Maintien = 371b3 de point, X=103620.0722 Y=49245.7502 Z= 0.0000 vers point, X=103620.0705 Y=49187.0630 Z= 0.0000 Longueur = 58.6872, Angle dans le plan XY = 270 Delta X = -0.0016, Delta Y = -58.6872, Delta Z = 0.0000 LIGNE Calque: "506" Espace: Espace objet Maintien = 371ad de point, X=103810.0724 Y=49255.0701 Z= 0.0000 vers point, X=103810.0705 Y=49187.0630 Z= 0.0000 Longueur = 68.0071, Angle dans le plan XY = 270 Delta X = -0.0019, Delta Y = -68.0071, Delta Z = 0.0000 LIGNE Calque: "506" Espace: Espace objet Maintien = 371af de point, X=104000.0727 Y=49264.3900 Z= 0.0000 Appuyez sur ENTREE pour continuer: vers point, X=104000.0705 Y=49187.0630 Z= 0.0000 Longueur = 77.3270, Angle dans le plan XY = 270 Delta X = -0.0022, Delta Y = -77.3270, Delta Z = 0.0000 LIGNE Calque: "506" Espace: Espace objet Maintien = 371a3 de point, X=104190.0722 Y=49246.6876 Z= 0.0000 vers point, X=104190.0705 Y=49187.0630 Z= 0.0000 Longueur = 59.6246, Angle dans le plan XY = 270 Delta X = -0.0017, Delta Y = -59.6246, Delta Z = 0.0000 LIGNE Calque: "506" Espace: Espace objet Maintien = 3718e de point, X=104360.0725 Y=49256.5929 Z= 0.0000 vers point, X=104360.0705 Y=49187.0630 Z= 0.0000 Longueur = 69.5299, Angle dans le plan XY = 270 Delta X = -0.0019, Delta Y = -69.5299, Delta Z = 0.0000 LIGNE Calque: "506" Espace: Espace objet Appuyez sur ENTREE pour continuer: Maintien = 37190 de point, X=104530.0727 Y=49264.3067 Z= 0.0000 vers point, X=104530.0705 Y=49187.0630 Z= 0.0000 Longueur = 77.2437, Angle dans le plan XY = 270 Delta X = -0.0022, Delta Y = -77.2437, Delta Z = 0.0000 LIGNE Calque: "506" Espace: Espace objet Maintien = 37192 de point, X=104700.0730 Y=49274.0157 Z= 0.0000 vers point, X=104700.0705 Y=49187.0630 Z= 0.0000 Longueur = 86.9527, Angle dans le plan XY = 270 Delta X = -0.0024, Delta Y = -86.9527, Delta Z = 0.0000 LIGNE Calque: "506" Espace: Espace objet Maintien = 37194 de point, X=104920.0731 Y=49278.0638 Z= 0.0000 vers point, X=104920.0705 Y=49187.0630 Z= 0.0000 Longueur = 91.0008, Angle dans le plan XY = 270 Delta X = -0.0025, Delta Y = -91.0008, Delta Z = 0.0000 Appuyez sur ENTREE pour continuer: LIGNE Calque: "506" Espace: Espace objet Maintien = 37196 de point, X=105140.0731 Y=49278.0638 Z= 0.0000 vers point, X=105140.0705 Y=49187.0630 Z= 0.0000 Longueur = 91.0008, Angle dans le plan XY = 270 Delta X = -0.0025, Delta Y = -91.0008, Delta Z = 0.0000 LIGNE Calque: "506" Espace: Espace objet Maintien = 37185 de point, X=105428.0731 Y=49278.0638 Z= 0.0000 vers point, X=105428.0705 Y=49187.0630 Z= 0.0000 Longueur = 91.0008, Angle dans le plan XY = 270 Delta X = -0.0025, Delta Y = -91.0008, Delta Z = 0.0000 LIGNE Calque: "506" Espace: Espace objet Maintien = 37187 de point, X=105728.0731 Y=49278.0638 Z= 0.0000 vers point, X=105728.0705 Y=49187.0630 Z= 0.0000 Longueur = 91.0008, Angle dans le plan XY = 270 Appuyez sur ENTREE pour continuer: Delta X = -0.0025, Delta Y = -91.0008, Delta Z = 0.0000 '; $subst = ""; $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