Separate country code from phone number

How can I separate the country code from a phone number?

I want +4712345678 to be separated into two terms: "country code" => "+47", "phone number" => "12345678"

See this post. You would need to re-write (in ruby) the code that is linked to.

Thank you!