$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