Second, I can't find anything that tells me where the symbols should go. All the .* etc. So for instance, this
Code: Select all
ereg("^їa-zA-Z0-9_\.\-]+@їa-zA-Z0-9\-]+\.їa-zA-Z0-9\-\.]+$", $addressI are confused.
Moderator: General Moderators
Code: Select all
ereg("^їa-zA-Z0-9_\.\-]+@їa-zA-Z0-9\-]+\.їa-zA-Z0-9\-\.]+$", $addresspreg_* family has more features and claimed to be faster in php manual. But choice is up to you. Use the variant which you understand better.Steveo31 wrote:Few questions on regex. One, which is technically "better", ereg (POSIX) or the preg_ family, Perl right?
Read the manual. PHP manual has really poor chapter on POSIX regexes, preg_* chapter is much better. But anyway, Google is your friend =)Steveo31 wrote: Second, I can't find anything that tells me where the symbols should go. All the .* etc. So for instance, thisValidates email address. My question is how do you determine where to put the +, ., etc?Code: Select all
ereg("^їa-zA-Z0-9_\.\-]+@їa-zA-Z0-9\-]+\.їa-zA-Z0-9\-\.]+$", $address
I are confused.
Code: Select all
* zero or more ("greedy"), similar to {0,}
+ one or more ("greedy"), similar to {1,}
? zero or one ("greedy"), similar to {0,1}
{n} exactly n times ("greedy")
{n,} at least n times ("greedy")
{n,m} at least n but not more than m times ("greedy")
*? zero or more ("non-greedy"), similar to {0,}?
+? one or more ("non-greedy"), similar to {1,}?
?? zero or one ("non-greedy"), similar to {0,1}?
{n}? exactly n times ("non-greedy")
{n,}? at least n times ("non-greedy")
{n,m}? at least n but not more than m times ("non-greedy")
If a curly bracket occurs in any other context, it is treated as a regular character.Code: Select all
їa-zA-Z0-9_\.\-]Code: Select all
їa-zA-Z0-9_.-]I could be wrong as I don't use ereg but if I remember correctly \w \b \s etc are not recognised in ereg functions which probably explains why your regex didn't work as expected.leenoble_uk wrote:It's probably just me but I found ereg to be quite flaky as I could never get it to work with things like \W \b \s etc.
Depends on what sort of programming you do, many people will only ever require basic email format validation and perhaps some regex to convert plain text URLs to an HTML link. In that sort of case it is not time efficient to learn regex when they could probably find some useful pre-rolled regex already available.Dave420 wrote:Regular expressions are one of the most important things you can learn as a PHP developer.
Try splitting it up into as many pieces as possible e.g....Steveo31 wrote:I know the basics, Tim, but I just can't get the gist of multiple huge matching syntax like the email thing.
Code: Select all
^їa-zA-Z0-9_\.\-]+
@
їa-zA-Z0-9\-]+
\.
їa-zA-Z0-9\-\.]+$