Ward Bekker wrote:
Whoops....last piece should read:
When i use this regexp: <control\sid=.+?>.+?\</control> it does not
handle the nesting correcly, returning this as a match: <control
id=1><control id=2></control>
Ward Bekker wrote:
Hi,
I need a regular expression that will match only the tags that have
nested tags inside them:
Input:
<control id=1><control id=2></control></control><control id=3></control>
Goal:
The regexp should match <control id=1><control id=2></control></control>
When i use this regexp: <control\sid=.+?>.+?\</control> it does not
handle the nesting correcly, returning this as a match: <control
id=1><control id=2></control></control>.
Thank you for your help,
Gr. Ward
I took the liberty of assuming you might have nested tags of more than two levels....
Regex regex = new Regex(@"
(<control\sid=.+?>.+?(?:</control>){2,})",
(RegexOptions) 0);
Sample input:
<control id=1><control id=2></control></control><control id=3></control>
<control id=1><control id=2><control id=4></control></control></control><control id=3></control>
Sample output:
Matching: <control id=1><control id=2></control></control><control id=3></control>
1 =»<control id=1><control id=2></control></control>«=
Matching: <control id=1><control id=2><control id=4></control></control></control><control id=3></control>
1 =»<control id=1><control id=2><control id=4></control></control></control>«=
--
Take care,
Ken
(to reply directly, remove the cool car. <sigh>)