Regular expression not working as expected

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Regular expression not working as expected

Post 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
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: Regular expression not working as expected

Post by yacahuma »

Solved. I needed to use () not []
Post Reply