dimanche 19 avril 2015

Uk postcode regex producing false possitives

I'm trying to pick out post codes from an array. I am using the post office's regex to find the matches.



$postcodeRegex = "/(GIR 0AA)|((([A-Z-[QVX]][0-9][0-9]?)|(([A-Z-[QVX]][A-Z-[IJZ]][0-9][0-9]?)|(([A-Z-[QVX]][0-9][A-HJKSTUW])|([A-Z-[QVX]][A-Z-[IJZ]][0-9][ABEHMNPRVWXY])))) [0-9][A-Z-[CIKMOV]]{2})/";

foreach( $content as $key => $line ){
if( preg_match($postcodeRegex, $line, $matches) !== false ) {
$points[] = $key;
}
}


But preg_match keeps is producing false positives. For example the line below is shown as a match.



HYPERLINK "mailto:email@address.com" email@address.com



My regex skills are very poor. How do i cut down on these false positives?


thanks


Aucun commentaire:

Enregistrer un commentaire