Skip to content

JS Regex match Canadian postal code from string

I would like to find the alphanumeric canadian postal code from a string. A string such as H9B2R1|taco|salsa|taco or if encoded, H9B2R1%7Ctaco%7Csalsa%7Ctaco. The result I’m looking for is the trimmed postal code before any special characters and/or non-alphanumeric values. How to I use split or regex t…

convert/rename keys in object?

I have an object looking like: I would like to rename all keys to be I’ve come up with this so far, which fails, likely because it’s not valid 🙂 So how do i rename the key and assign the correct value? Answer You can reduce over the Object.entries to create a new object (not an array which is what…