Re: regexp appears to be faulty (DONT actually think so)

From: Date: Tue, 24 Feb 2004 15:10:48 +0000
Subject: Re: regexp appears to be faulty (DONT actually think so)
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-178704@lists.php.net to get a copy of this message
Thanks Sven, You are quite right with your "some probs" comment. Do you know what the the switch is that catches only the least result? I now get (0)= (0)=[<fieldset attribute="hello"><legend>hello legend</legend>content of hello</fieldset><em>blah</em><fieldset attribute="goodbye">goodbye</fieldset>] (1)= (0)=[ attribute="hello"] (2)= (0)=[<legend>hello legend</legend>content of hello</fieldset><em>blah</em><fieldset attribute="goodbye">goodbye] as we can see the second fieldset is included in that which is between the fieldset tags! :-( Thanks everyone for you help including Mike (with the post out of chain). Henry "Sven" <svenie@gmx.li> wrote in message news:403B67FB.3090806@gmx.li... > Henry Grech-Cini schrieb: > ... > >> $regexp="/<fieldset([^>]*)>[^(<\/fieldset>)]*/i"; > ... > >>$result=extractFieldsets('test<fieldset attribute="hello">content > >>of > >>hello</fieldset><em>blah</em><fieldset > >>attribute="goodbye">goodbye</fieldset>'); > ... > >>And it produced; > >>(0)= > >>(0)=[<fieldset attribute="hello">con] > >>(1)=[<fieldset attribute="goodbye">goo] > >>(1)= > >>(0)=[ attribute="hello"] > >>(1)=[ attribute="goodbye"] > > hi, > > as it is defined in regex-spec: a '^' inside a char-group '[...]' > defines all chars, that aren't allowed, and not a string! > > so the first 't' of 'content' and the 'd' of 'goodbye' > don't match your > regex anymore. > > a start for a solution could be: > > <?php > $rx = '/<fieldset[^>]*>(.*)<\/fieldset>/i'; > ?> > > if you want to take care of your fieldset-attribs in your result, you > can set your brackets again: ([^>]*) > > some probs i can think of are nested fieldsets inside fieldsets (don't > know by head, if this is allowed by w3). and another prob: is that you > don't catch multiple fieldsets after another. i think there is a switch, > that catches only the least result. > > hth SVEN

« previous php.general (#178704) next »