RegExLib.com - The first Regular Expression Library on the Web!

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Pattern Title
Expression
^[abceghjklmnprstvxyABCEGHJKLMNPRSTVXY][0-9][abceghjklmnprstvwxyzABCEGHJKLMNPRSTVWXYZ] {0,1}[0-9][abceghjklmnprstvwxyzABCEGHJKLMNPRSTVWXYZ][0-9]$
Description
Canadian Postal Code / Codes / Canada / Zip Google for DFIOQU and you'll see where I got the info for this. Can anyone simplify this?
Matches
G3M 5T9 | C3M5T9
Non-Matches
Z3M 5T9 | W3M 5T9 | 5T9 C3M
Author Rating: Not yet rated. W. D.
Source
Your Rating
Bad Good

Enter New Comment

Title
 
Name
 
Comment
 
Spammers suck - we apologize. Please enter the text shown below to enable your comment (not case sensitive - try as many times as you need to if the first ones are too hard):

Existing User Comments

Title: Simplified
Name: Christina
Date: 2/8/2013 10:04:20 AM
Comment:
^[a-zA-Z][0-9][a-zA-Z]{0,1}[0-9][a-zA-Z][0-9]$ hope this helps.


Title: not the best solution
Name: Alex
Date: 6/15/2011 6:34:57 PM
Comment:
just make it case insensitive and it'll be a half of what you have (use "i" at the end of the expression)


Title: not the best solution
Name: Alex
Date: 6/15/2011 6:33:27 PM
Comment:
just make it case insensitive and it'll be a half of what you have (use "i" at the end of the expression)


Title: Simplification
Name: Nathon Dalton
Date: 9/28/2010 4:00:21 PM
Comment:
The following... [abceghjklmnprstvxyABCEGHJKLMNPRSTVXY][0-9] can be replaced with... [a-zA-Z][0-9]. If you wish to have all of them as a single character, you can do this... [a-zA-Z0-9]. So, the simplification of your entire regex (not saying it's correct, just simplifying it) is this... ^[a-yA-Y][0-9][a-zA-Z] {0,1}[0-9][a-zA-Z][0-9]$


Title: Senior Consultant
Name: Jill
Date: 6/25/2004 12:14:47 PM
Comment:
Excellent. This pattern disallows 12345-abcd, which others claiming to work against Canadian postal codes allowed.


Title: Simpler Corrected
Name: W. D.
Date: 2/13/2004 12:54:59 AM
Comment:
DFIOQU are not allowed anywhere, and W and Z aren't allowed in the number one position. So: ^(?i:(?![DFIOQUWZ])[a-z]\d(?![DFIOQU])[a-z] ?\d(?![DFIOQU])[a-z]\d)$ No 'U's are allowed: ^(?i:[a-ceghj-nprstvxy]\d[a-ceghj-nprstv-z] ?\d[a-ceghj-nprstv-z]\d)$


Title: Simpler
Name: Michael Ash
Date: 1/13/2004 10:45:49 AM
Comment:
Shorter anyway Either ^(?i:(?![DFIQUWZ])[a-z]\d(?![DFIQU])[a-z] ?\d(?![DFIQU])[a-z]\d)$ or ^(?i:[a-ceghj-nprst-vxy]\d[a-ceghj-nprst-v-z] ?\d[a-ceghj-nprst-v-z]\d)$


Copyright © 2001-2024, RegexAdvice.com | ASP.NET Tutorials