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

From: Date: Tue, 24 Feb 2004 15:04:27 +0000
Subject: Re: regexp appears to be faulty (DONT actually think so)
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-178702@lists.php.net to get a copy of this message
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 (#178702) next »