Re: [PHP-DB] regex question

2005-03-07 Thread Martin Norland
Chip Wiegand wrote:
I am writing some regex on a php form to validate input and have come up 
with this, for example -

if (empty($first) || !eregi(^[A-Za-z]+[- ]?[A-Za-z]+$, $first))
for checking a persons name. This allows a single name, or a hyphenated 
double name, or a non-hyphenated double name, and it works. My question is 
this - why is the third set followed by a '+' optional? I thought the + 
meant the preceding group is present 1 or more times. The ? means the 
preceding group is present 0 or more times. Why is it that when I put a ? 
in the place of the + after the last ] 

if (empty($first) || !eregi(^[A-Za-z]+[- ]?[A-Za-z]?$, $first))
the regex is broken?
The ? doesn't mean 0 or more, it means 'optional' - 0 or 1 times.
without specific examples on what works or what breaks, I can't explain 
it much better than this - but rest assured, that's your problem.

now I'm sitting here wondering if ?* and ?+ are interchangeable, and 
thinking so.

Cheers,
--
- Martin Norland, Sys Admin / Database / Web Developer, International 
Outreach x3257
The opinion(s) contained within this email do not necessarily represent 
those of St. Jude Children's Research Hospital.

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] regex question

2005-03-07 Thread W. D.
At 11:04 3/7/2005, Chip Wiegand wrote:
I am writing some regex on a php form to validate input and have come up 
with this, for example -

if (empty($first) || !eregi(^[A-Za-z]+[- ]?[A-Za-z]+$, $first))

for checking a persons name. This allows a single name, or a hyphenated 
double name, or a non-hyphenated double name, and it works. My question is 
this - why is the third set followed by a '+' optional? I thought the + 
meant the preceding group is present 1 or more times. The ? means the 
preceding group is present 0 or more times. Why is it that when I put a ? 
in the place of the + after the last ] 

if (empty($first) || !eregi(^[A-Za-z]+[- ]?[A-Za-z]?$, $first))

the regex is broken?

Regards,
Chip

If you want to add the capability for those weird, foreign
names [ ;^) ], take a look at the RegEx on this page:
http://www.RegExLib.com/UserPatterns.aspx?authorId=45511




Start Here to Find It Fast!™ - http://www.US-Webmasters.com/best-start-page/
$8.77 Domain Names - http://domains.us-webmasters.com/

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php