Re: [PHP] Another Regex Question (General)
On Wednesday, July 3, 2002, at 12:00 PM, Martin Clifford wrote: Does [a-zA-Z0-9] (yes, I know [:alnum:] is the same) mean that there can be a number, but it has to follow a letter? Or would you just do [a-zA-Z][0-9] to do that? That bracketed construction is called a character class. It represents any *one* of the contained characters. But not more than one. So there is no following at all, since for all intents and purposes the character class matches a single character (unless you use a qualifier like +, ?, or *). Erik Erik Price Web Developer Temp Media Lab, H.H. Brown [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Another Regex Question (General)
On Wed, Jul 03, 2002 at 12:00:50PM -0400, Martin Clifford wrote: Does [a-zA-Z0-9] (yes, I know [:alnum:] is the same) mean that there can be a number, but it has to follow a letter? Or would you just do [a-zA-Z][0-9] to do that? Your second question/statement is correct. --Dan -- PHP classes that make web design easier SQL Solution | Layout Solution | Form Solution sqlsolution.info | layoutsolution.info | formsolution.info T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] another REGEX question
Try $str = preg_replace(p.*?, ,$str); jack -Original Message- From: Julian Simpson [mailto:[EMAIL PROTECTED]] Sent: Thursday, August 02, 2001 5:16 PM To: [EMAIL PROTECTED] Subject: [PHP] another REGEX question I have a string can look like either of the following: psome stuff/p p align = leftsome stuff/p I want to use eregi_replace to take out the first p tag whether it be p or p align.. with a space I assumed that $str = eregi_replace (p.*, ,$str); but it matches the entire string and thus turns the whole string into one space. aparently regex will match the biggest possible match rather than the smallest my question is how do i get it to match the smallest. thanx in advance.. Julian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] another REGEX question
Hi Julian, personally, I'd take out both tags, using something like: $str = preg_replace(/\/?p.*?/i, , $str); Which gets rid of: p p align=whatever /p Or any case insensitive matches. That's probably just me though ;) James. Julian Simpson [EMAIL PROTECTED] wrote in message news:20010802214051.BGVV22490.femail29.sdc1.sfba.home.com@cr37888-a... $str = eregi_replace('p[^]*', ' ', $str); worked! thanx guys Julian At 5:19 PM -0400 8/2/01, Jack Dempsey wrote: Try $str = preg_replace(p.*?, ,$str); jack Or $str = eregi_replace('p[^]*', ' ', $str); This matches p (or P), followed by any character string that DOESN'T include a , then the trailing . Preg functions are faster, though. And, if you're interested in little speed tweaks, use single quotes - ' - rather than double quotes - - here. With double quotes, PHP searches the quoted string for variables or escape characters to replace. -steve -Original Message- From: Julian Simpson [mailto:[EMAIL PROTECTED]] Sent: Thursday, August 02, 2001 5:16 PM To: [EMAIL PROTECTED] Subject: [PHP] another REGEX question I have a string can look like either of the following: psome stuff/p p align = leftsome stuff/p I want to use eregi_replace to take out the first p tag whether it be p or p align.. with a space I assumed that $str = eregi_replace (p.*, ,$str); but it matches the entire string and thus turns the whole string into one space. aparently regex will match the biggest possible match rather than the smallest my question is how do i get it to match the smallest. thanx in advance.. Julian -- +-- Factoid: Of the 100 largest economies in the world, 51 are --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +--- corporations -- http://www.ips-dc.org/reports/top200text.htm ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] another REGEX question
Glad to hear...steve's post was a good one...something else to think about: sometimes people go for the .*? method, and sometimes the [^]* way...they give the same results in most cases, but the .*? will match the least amount it can, using the dot...the negation will match anything...so, unless you have the s flag enabled, the . will not match a newline, while the negation will... Just a lil extra info jack -Original Message- From: Julian Simpson [mailto:[EMAIL PROTECTED]] Sent: Thursday, August 02, 2001 5:42 PM To: Steve Edberg; [EMAIL PROTECTED] Subject: RE: [PHP] another REGEX question $str = eregi_replace('p[^]*', ' ', $str); worked! thanx guys Julian At 5:19 PM -0400 8/2/01, Jack Dempsey wrote: Try $str = preg_replace(p.*?, ,$str); jack Or $str = eregi_replace('p[^]*', ' ', $str); This matches p (or P), followed by any character string that DOESN'T include a , then the trailing . Preg functions are faster, though. And, if you're interested in little speed tweaks, use single quotes - ' - rather than double quotes - - here. With double quotes, PHP searches the quoted string for variables or escape characters to replace. -steve -Original Message- From: Julian Simpson [mailto:[EMAIL PROTECTED]] Sent: Thursday, August 02, 2001 5:16 PM To: [EMAIL PROTECTED] Subject: [PHP] another REGEX question I have a string can look like either of the following: psome stuff/p p align = leftsome stuff/p I want to use eregi_replace to take out the first p tag whether it be p or p align.. with a space I assumed that $str = eregi_replace (p.*, ,$str); but it matches the entire string and thus turns the whole string into one space. aparently regex will match the biggest possible match rather than the smallest my question is how do i get it to match the smallest. thanx in advance.. Julian -- +-- Factoid: Of the 100 largest economies in the world, 51 are --+ | Steve Edberg University of California, Davis | | [EMAIL PROTECTED] Computer Consultant | | http://aesric.ucdavis.edu/ http://pgfsun.ucdavis.edu/ | +--- corporations -- http://www.ips-dc.org/reports/top200text.htm ---+ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] another REGEX question
hahah that had two interesting effects the first was that it left the and the second was that it turned off all the highlighting in my editor due to the ? any idea how to include the braces in the match and perhaps not using the ? string for the sake of convenience :) Julian 8/2/01 5:19:03 PM, Jack Dempsey [EMAIL PROTECTED] wrote: Try $str = preg_replace(p.*?, ,$str); jack -Original Message- From: Julian Simpson [mailto:[EMAIL PROTECTED]] Sent: Thursday, August 02, 2001 5:16 PM To: [EMAIL PROTECTED] Subject: [PHP] another REGEX question I have a string can look like either of the following: psome stuff/p p align = leftsome stuff/p I want to use eregi_replace to take out the first p tag whether it be p or p align.. with a space I assumed that $str = eregi_replace (p.*, ,$str); but it matches the entire string and thus turns the whole string into one space. aparently regex will match the biggest possible match rather than the smallest my question is how do i get it to match the smallest. thanx in advance.. Julian -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]