format string (postcode) in ruby

Posted by noddy on Stack Overflow See other posts from Stack Overflow or by noddy
Published on 2010-04-08T09:06:37Z Indexed on 2010/04/08 9:13 UTC
Read the original article Hit count: 422

Filed under:
|
|
|
|

I need to re-format a list of UK postcodes and have started with the following to strip whitespace and capitalize:

postcode.upcase.gsub(/\s/,'')

I now need to change the postcode so the new postcode will be in a format that will match the following regexp:

^([A-PR-UWYZ0-9][A-HK-Y0-9][AEHMNPRTVXY0-9]?[ABEHMNPRVWXY0-9]? {1,2}[0-9][ABD-HJLN-UW-Z]{2}|GIR 0AA)$

I would be grateful of any assistance.

© Stack Overflow or respective owner

Related posts about ruby

Related posts about regex