RE: [PHP] Regular Expression

From: Date: Mon, 04 Aug 2003 21:55:35 +0000
Subject: RE: [PHP] Regular Expression
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-158195@lists.php.net to get a copy of this message
> 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 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"; > } You are using a + as the modifier on the space between p.o. and box. + means 1 or more. Option 3 does not have a space. Try using * which is 0 or more, or ? which is 0 or 1.

« previous php.general (#158195) next »