in reply to String Manipulation Help Required
I have tried in another way using regex, but this can be done still more efficiently.
$str = '<businesses> <entity name="Retail"> <description>Products and items available in retail</description +> <product min="0" max="3"> <description>Product information</description> <item name="Title"> <description>Title</description> <text maxlength="80" size="65" /> </item> </product> </entity> <item name="Patrol"> <description>Title</description> <text maxlength="80" size="65" /> </item> <entity name="Sports"> <description>Sports Items</description> <product min="0" max="3"> <item name="Title"> <description>Title</description> <text maxlength="80" size="65" /> </item> </product> </entity> </businesses>'; $str =~ s/(<entity)([^>]+)>((?:(?!(?:<product)).)*)(<product (min="[^" +]*" max="[^"]*")>)/<block$2 $5>$3$4/gsi; $str=~ s/<\/product>\s*<\/entity>/<\/block>/gsi; print "$str";
This gives the following output.
<businesses> <block name="Retail" min="0" max="3"> <description>Products and items available in retail</description +> <product min="0" max="3"> <description>Product information</description> <item name="Title"> <description>Title</description> <text maxlength="80" size="65" /> </item> </block> <item name="Patrol"> <description>Title</description> <text maxlength="80" size="65" /> </item> <block name="Sports" min="0" max="3"> <description>Sports Items</description> <product min="0" max="3"> <item name="Title"> <description>Title</description> <text maxlength="80" size="65" /> </item> </block> </businesses>
updated:
Prasad
|
|---|