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

Please support RegExLib Sponsors

Sponsors

Regular Expression Details

Title Test Find Canada Postal Codes
Expression
^(?<full>(?<part1>[ABCEGHJKLMNPRSTVXY]{1}\d{1}[A-Z]{1})(?:[ ](?=\d))?(?<part2>\d{1}[A-Z]{1}\d{1}))$
Description
This is a combination of Jerry Schmersahl's (http://regexlib.com/REDetails.aspx?regexp_id=930) US ZIP Code regex and John Alpha's (http://regexlib.com/REDetails.aspx?regexp_id=2754) Canadian Postal Code regex. It takes a Canadian postal code with or without a space and matches the first three digits to the named reference 'part1', the second three digits to the named reference 'part2', and the entire code (if a match) to the named reference 'full'
Matches
M4S 1G9 | M4S1G9 | K1A0B1 | K1A 0B1
Non-Matches
123 ABC | 5A2A2B | K1A 0B | M4S | 90210
Author Rating: The rating for this expression. Christopher Congdon
Source Thanks to Jerry Schmersahl and John Alpha
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

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