Originally Posted by rangeshram
close the div tags, where only opening divisional tags such div1, div2 and div3 elements present inthe xml file.
I think this problem is too complex for regular expressions (although I may be wrong).
In this case, you are not really trying to match a set pattern.
Matching tags on one line should be simple enough.
Should match any div with a number in it that may have something after it and ends in a new line.
Matching tags across multiple lines is alot more trouble.
<div1> has to know that <div2> is inside it because of the indenting. However, that means that the match has to remember the indeting before the <div1> (in this case none) check it against the indenting of <div2> and see if div2 has more.
I don't think that regex can do that; they have no built in memory.
I think it would be better to read the xml file in line by line, check the indenting before any tags and use some sort of stack to hold tags that need to be closed on other lines.
Not having used any perl, I cannot really be of help.