Re: Regular Expression
| From: | Curt Zirzow | Date: | Tue, 05 Aug 2003 02:20:15 +0000 |
| Subject: | Re: Regular Expression | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-158231@lists.php.net to get a copy of this message | ||
* Thus wrote Ralph Guzman (ralph@nqionline.com):
> Been working on this one for a while but can't get it working properly.
> I need a regular expression to match if address is
>
> 1. PO Box
> 2. P.O. Box
> 3. P.O.Box
>
> I'm using /i to make this case insensitive.
/p\.?o\.?\s*box/i
>
> I got it working with 1 & 2, but it's still not matching 3. Any
> suggestions?
>
> if(preg_match( "/p[\.]o\.* +box/i", trim($_POST['address'])){
> echo "Address is P.O. BOX";
> }
hmm.. if i read that right that will only match #2 (I'm not sure
that the [] includes a null match or not.) Also the character class
[] has special escapes, you dont need to escape the period because
the period is literal there.
there are other alternatives people might also type like:
p/o box
thus my original pattern becomes:
/p[.\\]?o\.?\s*box/i
HTH,
Curt
--
"I used to think I was indecisive, but now I'm not so sure."