Re: [PHP4BETA] Problem with preg_match_all

From: Date: Tue, 01 Feb 2000 14:30:05 +0000
Subject: Re: [PHP4BETA] Problem with preg_match_all
References: 1 2 3  Groups: php.version4 
Request: Send a blank email to php-version4+get-9622@lists.php.net to get a copy of this message
Vadim, Here's what the author of PCRE library had to say about this. You are looking for a line that contains at least two occurces of "<td". In the file you sent, there are no such lines. Or are you passing the entire file as one string? (I guess the /s option suggests that you are.) In that case, I'm not surprised it takes a long time. All those occurrences of .* are going to kill performance. Instead of, for example bgcolor=".*" you should write bgcolor="[^"]*" Otherwise the .* is going to swallow the whole file, and then start backtracking. Since you have lots of .* occurrences, it's going to take forever. There are going to be a lot of mismatches on other quotes as well, making things worse. I did a simple test. Just changing the .* strings that are inside "" made it return "no match" pretty instantly, instead of hanging. Changing the other .* strings would improve it still more. Regular expressions do sometimes need a bit of thought. On Thu, 27 Jan 2000, Vadim Tkachenko wrote: > Attached html > > ----- Original Message ----- > From: Andrei Zmievski <andrei@ispi.net> > To: Vadim Tkachenko <vvtk@stealthcomp.com> > Cc: php4beta <php4beta@lists.php.net> > Sent: Thursday, January 27, 2000 7:39 PM > Subject: Re: [PHP4BETA] Problem with preg_match_all > > > > On Wed, 26 Jan 2000, Vadim Tkachenko wrote: > > > I have an html file (size 4 Kb) > > > I put this file to variable $result; > > > > > > When I try to use preg_match_all as below > > > $fnd=preg_match_all("|\<td bgcolor=\".*\" width=\".*\" > > > class=\".*\"\>\<b\>(.*)\<\/b\>\<\/td\>.*\<td > > > width=\".*\" align=\".*\" > > > class=\".*\"\>(.*)\<\/td\>\<td width=\".*\" > > > align=\".*\" > > > class=\".*\"\>(.*)\<\/td\>\<td width=\".*\" > > > align=\".*\" > > > class=\".*\"\>(.*)\<\/td\>|msiU",$results,$brances); > > > > > > it seems that preg_match_all runs in endless loop. > > > > > > By the present moment the method runs about 17 min. > > > > What does $results look like? Can you simplify it a bit still reproducing > the problem? > > > > -Andrei > > > > -- > > PHP 4.0 Beta Mailing List > > <http://www.php.net/version4/> > > To unsubscribe, e-mail: php4beta-unsubscribe@lists.php.net > > For additional commands, e-mail: php4beta-help@lists.php.net > > To contact the list administrators, e-mail: php4beta-admin@lists.php.net > > Product Availability > Part Number: 043026 > Location [1]Quantity On order from vendor [2]ETA Date * > MIAMI, FL 0 0 > SUWANEE, GA 0 0 > SWEDESBORO, NJ 0 0 > SOUTH BEND, IN 2 0 > FT WORTH, TX 0 0 > FONTANA, CA 0 0 > RALEIGH, NC 0 0 > FREDERICK, MD 0 0 > Description: [3]MEGA RAID CLUSTER KIT1400 U2 LVDW RACK DISK SUBSYS > Status: New > > [[4]need help?] > Quantities showing as "***" indicate that this product is a highly > constrained item and may not be available. Please contact your Sales > Representative for further information. > * The ETA Date information displayed was provided to Tech Data by the > vendor and may be subject to change. Because this is a vendor-provided > date, product availability on this date cannot be guaranteed. > > References > > 1. javascript:onQua(); > 2. javascript:onEta(); > 3. file://localhost/tmp/product_detail.asp?TDPart=043026 > 4. javascript:OnHelp(); -Andrei * Entropy isn't what it used to be. *

« previous php.version4 (#9622) next »