in reply to String Manipulation Help Required

TIMTOWDI

$strFile=' <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> '; $strFile=~s#<entity ([^>]+)>\s*(.+?)<product (min="[^"]+" max="[^"]+") +>#<block $1 $3>\n$2#gs; $strFile=~s#</product>\s*</entity>#</block>#gs; print "\n$strFile";

Thanks,
Gopal.R

Replies are listed 'Best First'.
Re^2: String Manipulation Help Required
by Anonymous Monk on Jun 29, 2005 at 09:21 UTC

    Thanks Gopal.R

    Your solution is of great help. Thanks.

    The Regex failed when the "<entity></entity> is changed to "<item></item>". This was attempeted with the intention that the first level element have the same name.

    The Error can be over come, if "</item>" tag does not occur in the search string. Something like below

    $strFile=~s#<entity ([^>]+)>\s*(.+?)<i>negating regex here </i><produc +t (min="[^"]+" max="[^"]+")

    Please advice solution as I am a novice Regex Developer.

    Thanks in advance.