Regex Series: Canadian Postal Codes

Published by bangyen in

Write a regular expression that matches any valid Canadian postal code with any of the following formats:

A1A 1A1
A1A-1A1
A1A1B1

Make the match case insensitive.

Examples

"M3M 0A9" ➞ true

"m4c-1t1" ➞ true

"m45 1t1" ➞ false

"M4C-1T1Z" ➞ false

Notes

This challenge is designed to use Regex only.

Watch a quick demo on how Edabit works.