Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
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
  • 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
Processing...

Test String

Substitution
Processing...

Code Generator

Generated Code

$re = '/(<(?P<tag1>\w+)>)\n(?\'tag2\'[\w\<\>.]+)\n<\/(?P=tag1)>/m'; $str = '<?xml version="1.0" encoding="utf-8" standalone="no"?> <Annotations> <Version> 1 </Version> <Container> <PageNumber> 1 </PageNumber> <Size> <Width> 3979.2 </Width> <Height> 5611.2 </Height> </Size> <Offset> <X> 0 </X> <Y> 0 </Y> </Offset> <CalibrationScale> 1 </CalibrationScale> <IsVisible> true </IsVisible> <IsEnabled> true </IsEnabled> <UserData> </UserData> <CalibrationUnit> 0 </CalibrationUnit> <Objects> <OnLoad> <RotateAngle> 0 </RotateAngle> <ScaleX> 1 </ScaleX> <ScaleY> 1 </ScaleY> <Offset> <X> 0 </X> <Y> 0 </Y> </Offset> </OnLoad> <Object> <ObjectType> Leadtools.Annotations.Engine.AnnStampObject </ObjectType> <AssemblyName> Leadtools.Annotations.Engine </AssemblyName> <OnLoad> <RotateAngle> 0 </RotateAngle> <ScaleX> 1 </ScaleX> <ScaleY> 1 </ScaleY> <Offset> <X> 0 </X> <Y> 0 </Y> </Offset> </OnLoad> <IsVisible> true </IsVisible> <IsSelected> false </IsSelected> <IsLocked> false </IsLocked> <Password> </Password> <GroupName/> <Hyperlink/> <FixedStateOperations> 8 </FixedStateOperations> <RotateGripper> 240 </RotateGripper> <RotateCenter> <X> NaN </X> <Y> NaN </Y> </RotateCenter> <Points> <Point> <X> 2400 </X> <Y> 741.6 </Y> </Point> <Point> <X> 4029.6 </X> <Y> 741.6 </Y> </Point> <Point> <X> 4029.6 </X> <Y> 1380 </Y> </Point> <Point> <X> 2400 </X> <Y> 1380 </Y> </Point> </Points> <Fill/> <Labels> <Label> <Key> AnnObjectName </Key> <IsVisible> false </IsVisible> <LabelRestriction> 0 </LabelRestriction> <Text/> <OriginalPosition> <X> 2400 </X> <Y> 741.6 </Y> </OriginalPosition> <Offset> <X> NaN </X> <Y> NaN </Y> </Offset> <Background/> <Foreground> <SolidColorBrush> <Color> Transparent </Color> </SolidColorBrush> </Foreground> <Font> <FamilyName> Arial </FamilyName> <Size> 11 </Size> <Stretch> Normal </Stretch> <Weight> Normal </Weight> <Style> Normal </Style> <TextDecoration> 0 </TextDecoration> </Font> <OffsetHeight> true </OffsetHeight> </Label> </Labels> <Stroke> <Fill> <SolidColorBrush> <Color> Transparent </Color> </SolidColorBrush> </Fill> <Thickness> 0 </Thickness> <MiterLimit> 0 </MiterLimit> <DashCap> Flat </DashCap> <StartLineCap> Round </StartLineCap> <EndLineCap> Round </EndLineCap> <LineJoin> Round </LineJoin> <DashOffset> 0 </DashOffset> <Dashes/> <StrokeAlignment> Center </StrokeAlignment> </Stroke> <SelectionStroke> <Fill> <SolidColorBrush> <Color> Blue </Color> </SolidColorBrush> </Fill> <Thickness> 4 </Thickness> <MiterLimit> 0 </MiterLimit> <DashCap> Flat </DashCap> <StartLineCap> Round </StartLineCap> <EndLineCap> Round </EndLineCap> <LineJoin> Round </LineJoin> <DashOffset> 0 </DashOffset> <Dashes/> <StrokeAlignment> Center </StrokeAlignment> </SelectionStroke> <Font> <FamilyName> Arial </FamilyName> <Size> 11 </Size> <Stretch> Normal </Stretch> <Weight> Normal </Weight> <Style> Normal </Style> <TextDecoration> 0 </TextDecoration> </Font> <ObjectId> -16 </ObjectId> <ObjectTag/> <Metadata> <Item> <Key> Subject </Key> <Value> Annotate_1 </Value> </Item> <Item> <Key> Author </Key> <Value> Author1 </Value> </Item> <Item> <Key> Modified </Key> <Value> 2021-03-04 21:50:12 </Value> </Item> <Item> <Key> Title </Key> <Value> cvadmin </Value> </Item> <Item> <Key> Content </Key> <Value> SIGN_cvadmin 3/4/2021 9:49:54 PM </Value> </Item> <Item> <Key> Created </Key> <Value> 2021-03-04 21:50:12 </Value> </Item> </Metadata> <Reviews/> <UserId/> <LayerId/> <Opacity> 1 </Opacity> <Picture> <PictureData> Null </PictureData> <PictureSource> D:/GitLeadtools20And21MergedWorkSpace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/CVWeb/Temp/Apurba DB/272/12102/2.png </PictureSource> <PictureWidth> 4710.973077661264 </PictureWidth> <PictureHeight> 1295.5175963568474 </PictureHeight> </Picture> </Object> </Objects> </Container> </Annotations>'; $subst = "<${tag1}>\n\t${tag2}\n</${tag1}>"; $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