Hi,
I have 2 alternative regexes to check for a valid UK Postcode. I know that they probably do not check accurately, however I believe the 2 regexes are identical but do not produce the same output.
Regex 2 will pass postcodes such as 'AA1 11A' and 'AA1 1A1' which should fail.
What have I done wrong / why do they pass?
Thanks,
Chris
I have 2 alternative regexes to check for a valid UK Postcode. I know that they probably do not check accurately, however I believe the 2 regexes are identical but do not produce the same output.
Code:
[blue]Regex 1 (classes) (works as expected):[/blue]
if($_=~s/^([A-Za-z]{1,3}[0-9]{1}|[A-Za-z]{1,2}[0-9]{2})([0-9]{1}[A-Za-z]{2})$/$1 $2/){print "$_ > Passed<br>";}
[blue]Regex 2 (shorthands) (does not work as expected):[/blue]
if($_=~s/^(\w{1,3}\d{1}|\w{1,2}\d{2})(\d{1}\w{2})$/$1 $2/){print "$_ > Passed<br>";}
Regex 2 will pass postcodes such as 'AA1 11A' and 'AA1 1A1' which should fail.
What have I done wrong / why do they pass?
Thanks,
Chris