RE: [PHP] Help with simple regular expression

From: Date: Mon, 25 Jun 2001 19:31:29 +0000
Subject: RE: [PHP] Help with simple regular expression
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-55146@lists.php.net to get a copy of this message
exactly. use the non-greedy "?" with the perl regex's to have perl match the least amount of characters it can. preg_match('/<blah(.*?)>/', $text, $matches) in the case of perl regexp's, you have to specifically tell the regexp not to be greedy. the "?" regexp modifier is how you do this. (otherwise, the regexp will try and match the maximum amount of text that it can, which usually isnt what you want, since it'll match *eveything* between "blah" and the last occurance of ">" in the text) so, in the case of this text: <blah now> sasfd asdf asdf </html> the greedy will match something like this: now> sasfd asdf asdf </html> and the non-greedy will match something like this: now > -----Original Message----- > From: Richard Lynch [mailto:ceo@l-i-e.com] > Subject: Re: [PHP] Help with simple regular expression > > > That's because POSIX is greedy. Or Perl is greedy. Whatever. > > When one of them does that, use the other one. > > Instead of eregi, use pregi. > > Disclaimer: What I know about Regex could fit in a matchbook. > > -- > WARNING richard@zend.com address is an endangered species -- Use > ceo@l-i-e.com > Wanna help me out? Like Music? Buy a CD: > http://l-i-e.com/artists.htm > Volunteer a little time: http://chatmusic.com/volunteer.htm > ----- Original Message ----- > From: "Aral Balkan" <aral@aralbalkan.com> > Newsgroups: php.general > Sent: Sunday, June 24, 2001 7:34 PM > Subject: [PHP] Help with simple regular expression > > > > Hi all, > > > > I'm trying to match the body tag in an HTML file (eg. <body > > bgcolor="ffffgg">) with the following regular expression and eregi: > > > > <body.*> > > > > Unfortunately it matches everything from the body tag onwards and doesn't > > stop at the greater-than sign. It should be simple thing but I'm stumped! > To > > me the regex reads match string that begins with <body followed by zero or > > more of anything and ending with a greater-than sign. > > > > Any help would be greatly appreciated! :) > > > > Aral > > ______________________________ > > (aral@kismia.com) > > New Media Producer, Kismia, Inc. > > (aral@american.edu) > > Adj. Prof., American University > > ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ > > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > For additional commands, e-mail: php-general-help@lists.php.net > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#55146) next »