Regular Expressions 101

Save & Share

  • Regex Version: ver. 5
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

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

$re = '/<TEXT>\s*begin \d+ (?>[^e]+|e(?!nd\s*<\/TEXT>))*end\s*<\/TEXT>/m'; $str = '<HTML> <BODY STYLE="font: 10pt Times New Roman, Times, Serif"> <TEXT> begin 644 h52992h5299202.gif M1TE&.#EA>P`>`,0``\']_?S\\_/^_O[P\\/#[^_OU]?7Q\\?\'X^/CY^?GZ^OK\\_/ MSV]O;T]/3]_?WR\\O+U!04````/___P`````````````````````````````` M`````````````````````````"\'Y!```````+`````![`!X```7_8"2.9&F> M:*JN+"DP22O/=&W?Z`(M>.__0-4`T@@:C\\A689=L-0B$!`(!`""@S:P)$M"B M!(#"$$(NEP,`0E,AR!X@"N_I`1D$&-6JM,H8PXX-$`5-`@9=<B8(#\'$K5$,\' M1H$0:D@,$#&(*PD`*0(.<$8!@D@*$`:9*P)D*@D0G$&?"$A+KZ@H;PPJ;[4^ MI09M1Z)%MBB6E"<(ID8&9,!!`G;$7T-?2P[./F]DLD8`$)`F"@0\'",->;X<E M")\\,V#W0`T.\\/IX#YA$"8F2BEW)+/",:(!#EX!@0\'0!:S>OQ!F"$!&+L%(C# MS($<4<#`5#S@SD:#`@#:&#A%P%6W22):_QG@J(`/&7`N`#@`U[+`J0A4`-P[ M`0V"B`,&!A2`^>.%F5\\*@S08*4+!$`,`%HS9$4/``2MAIA:P=(;?O@0=?T*P M&&%;DP1>XT%H]P/MO@!3S;P-P$RNF0$+$+3:!X!!7:@=EV`BXQ!)L@()I)*Q MPTT&@@(!O)K"<X``5[D.%E2YDN!O90+F7I(8N)C1"&%BQQ:X$@P"L%:11[5` M4%=NX8!0")@N`8:MB0*W11#X-("7@W3XELBU$SER8QFETI5<F$(!,Z$<(WB[ M*2W"1Z(F31#(`[DYLT$T1)F>?AIYB5)<G*D:8+`["?8T"(3M%&U$4A%1I:#- M??%09Y]V*/5`VU0*WF`B@@X.KN"4(%!X0]^!*\'A37PT*$\'6")?(-L9,*$Y8Q MP&X8DJ##B$DL04(IZ,U``&0&%+!?BH9D$D4)V:68A"KN^2BD#R4%-^21-O2( \'Y)(TA```.S\\_ ` end </TEXT> <TEXT>losses occurring in the third quarter and from weather </TEXT> </BODY>'; $subst = "<TEXT><\/TEXT>"; $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