Title |
Test
Find
Canadian Postal Code
|
Expression |
\b[A-Z-[DFIOQUWZ]]\d[A-Z-[DFIOQU]]\ +\d[A-Z-[DFIOQU]]\d\b |
Description |
Find out Canadian Postal Code in the text or html file or xml file |
Matches |
L4X 1S9 |
Non-Matches |
12345 |
Author |
Rating:
Not yet rated.
Balram Watwani
|
Source |
|
Your Rating |
|
Title: BELOW
Name: not impressed
Date: 5/16/2009 12:43:48 PM
Comment:
the two comments below including the guy who thinks the other's regex needs huge improvement are both wrong. their regex don't follow Canadian postal guide lines. for example, Z is not a valid character for the first letter of a postal code. so sad when people are so arrogant and yet so stupid.
Title: Ok
Name: TheGuitarist
Date: 2/17/2008 1:20:27 PM
Comment:
You just have to change the case of your string before applying the regex...
Title: Needs Improvement
Name: Huge
Date: 6/7/2007 2:53:21 PM
Comment:
\b[ABCEGHJKLMNPRSTZXYabceghjklmnprstvxy]\d[ABCEGHJKLMNPRSTZXYabceghjklmnprstvxy]\ +\d[ABCEGHJKLMNPRSTZXYabceghjklmnprstvxy]\d\b
This is OK, but, you have v allowed in lowercase, but not in uppercase. You have Z allowed in uppercase, but not lowercase. This is not consistent. Here's mine:
"^[ABCEGHJKLMNPRSTVXYZabceghjklmnprstvxyz][0-9][ABCEGHJKLMNPRSTVVXYZabceghjklmnprstvxyz] +[0-9][ABCEGHJKLMNPRSTVXYZabceghjklmnprstvxyz][0-9]$"
Title: Looks good, but missing a small functionality
Name: Subhadip
Date: 3/6/2007 3:27:06 PM
Comment:
What happens if the user enters a postal code: a1a 1a1, which is a valid one, but when matched against the pattern, it will evaluate to a wrong one. So, I have come out with the following one: \b[ABCEGHJKLMNPRSTZXYabceghjklmnprstvxy]\d[ABCEGHJKLMNPRSTZXYabceghjklmnprstvxy]\ +\d[ABCEGHJKLMNPRSTZXYabceghjklmnprstvxy]\d\b
Anybody can refine it.