Page 1 of 1

Regular expression not working as expected

Posted: Fri Dec 03, 2010 6:33 pm
by yacahuma
need to validate the following string
[ANYTHING] [OPTIONS] [ANYTHING] WHERE OPTIONS = Street or Ave or Carr

Code: Select all

$line2 = 'E-20 Street Juanita Agil';
$reg = '/^.*\s[Street|Ave|Carr]\s.*$/i';
if (preg_match($reg, $line2, $matches)) 
   return true;
else
  return false;

What am I missing? Thank you

Re: Regular expression not working as expected

Posted: Sat Dec 04, 2010 5:38 am
by yacahuma
Solved. I needed to use () not []