Re: [PHP] regexps
I need to use regular expressions, but i found that the current Perl-compaitable API unuseful in my case, infact i need to get the positions of every match to the pattern and i found nothing in the Manual that does so, does any one know a way to do this (the only one i found is specific to PHP 4.3.0) You could match all of the strings and then use one of the other string functions to find the position. ---John Holmes... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexps
using any of the string functions on the output would ofcourse cause a performance drawback (do you agree with me?), i had used a combination of string functions to do instead of regexps, which one will be faster as you think ? where can i suggest such a function on the current regexps API ? Thanx, Khalid Al-Kary _ Protect your PC - get McAfee.com VirusScan Online http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] regexps
using any of the string functions on the output would ofcourse cause a performance drawback (do you agree with me?), i had used a combination of string functions to do instead of regexps, which one will be faster as you think ? It depends on exactly what your doing, how much text you have, and why you need to match the position as well as the text. where can i suggest such a function on the current regexps API ? I don't know. ---John W. Holmes... PHP Architect - A monthly magazine for PHP Professionals. Get your copy today. http://www.phparch.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] regexps
using any of the string functions on the output would ofcourse cause a performance drawback (do you agree with me?), i had used a combination of string functions to do instead of regexps, which one will be faster as you think ? Hi, i made some basic bench and see that it really depends... try to make some basic search like ^[0-9]{1,4}$ how can u do this ? with substr, strlen, strstr and ifthenelse ? i found really faster to use preg_match(), which is really faster than if (ereg())... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] regexps
here are two regexps that might do what you want \w matches alphanum (1-9a-zA-z) IMO, the best way to check for non-alphanum chars is to check for \W (upper case is negation of alphanum, which will match only non-alphanum). if (preg_match('/^\w+$/', $data)) { print entirely alphanum } if (preg_match('/\W+/', $data)) { print Contains non-alphanum!!; } -Original Message- From: Kurth Bemis [mailto:[EMAIL PROTECTED]] Sent: Wednesday, August 08, 2001 4:43 PM To: [EMAIL PROTECTED] Subject: [PHP] regexps i need to find out if a string (user imputed) conatins numbers. I want only a-zA-Z to be in a field. (their name for exampleand city)...i have the following however my regexps are VERY weak as i am a beginner. function validatetext($text){ if (is_string($text)== 1){ return good; }else{ return bad; } } ~kurth -- 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] regexps
In article [EMAIL PROTECTED], [EMAIL PROTECTED] (Scott) wrote: here are two regexps that might do what you want \w matches alphanum (1-9a-zA-z) (0-9a-zA-Z_) actually. Don't forget that zero and underscore! IMO, the best way to check for non-alphanum chars is to check for \W (upper case is negation of alphanum, which will match only non-alphanum). Yep, works nicely as long as including the underscore as one of the alphanumeric character is acceptable for your purposes. -- CC -- 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] regexps
if (preg_match(/\d/, $data) { print 'The $data contained a number'; } On 2001.08.09 07:05 scott [gts] wrote: here are two regexps that might do what you want \w matches alphanum (1-9a-zA-z) IMO, the best way to check for non-alphanum chars is to check for \W (upper case is negation of alphanum, which will match only non-alphanum). if (preg_match('/^\w+$/', $data)) { print entirely alphanum } if (preg_match('/\W+/', $data)) { print Contains non-alphanum!!; } -Original Message- From: Kurth Bemis [mailto:[EMAIL PROTECTED]] Sent: Wednesday, August 08, 2001 4:43 PM To: [EMAIL PROTECTED] Subject: [PHP] regexps i need to find out if a string (user imputed) conatins numbers. I want only a-zA-Z to be in a field. (their name for exampleand city)...i have the following however my regexps are VERY weak as i am a beginner. function validatetext($text){ if (is_string($text)== 1){ return good; }else{ return bad; } } ~kurth -- 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] -- 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] regexps
Why don't you do a function with an ereg inside? I don't think that exist a command like that... Rom - Original Message - From: Elliot L. Tobin [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, January 16, 2001 11:59 AM Subject: [PHP] regexps Is there a way to call one regexp on multiple variables, in one statement? In Perl, I'd do: s/this/that for ($var1, $var2, $var3); tia.. and please reply directly. [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] -- 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] regexps
Most of the preg_ functions support arrays of values as input parameters. It's all in the documentation. "Elliot L. Tobin" wrote: Is there a way to call one regexp on multiple variables, in one statement? In Perl, I'd do: s/this/that for ($var1, $var2, $var3); tia.. and please reply directly. [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] -- Monte Ohrt [EMAIL PROTECTED] http://www.ispi.net/ -- 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] regexps
You could loop it with foreach (which I think is the same way Perl handles the ex you gave). foreach ($myArr as $myStr) { $myStr = ereg_replace($regexp, $myStr); } Note quite "one statement", but if you really wanted to shorted it (and in the opinion of most sacrafice readability), you could say: foreach ($myArr as $myStr) $myStr = ereg_replace(...etc...); --Toby - Original Message - From: "Elliot L. Tobin" [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, January 16, 2001 11:59 AM Subject: [PHP] regexps Is there a way to call one regexp on multiple variables, in one statement? In Perl, I'd do: s/this/that for ($var1, $var2, $var3); tia.. and please reply directly. [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] -- 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]