Created
February 3, 2009 21:42
-
-
Save paddor/57782 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
nummern = [ | |
"+41 ( 0 ) 79-123 4567", | |
"+41-79-123 4567", | |
"079 123 45 67", | |
"+41 ( 079 ) 123 67 90", | |
] | |
# fuer jede nummer ... | |
nummern.each do |nr| # aktuelle nummer ist in variable "nr" | |
# ersetze alle o (ignore case) mit 0 | |
nr.gsub! /o/i, "0" | |
# loesche sowas wie "( 0 )" | |
nr.sub! /\(\s*0\s*\)/, "" | |
# mache "79" aus "( 079 )" | |
nr.sub! /\(\s*0+(\d+)\s*\)/, '\1' | |
# loesche alle nicht-Ziffern | |
nr.gsub! /\D/, "" | |
# loesche fuehrende Nullen | |
nr.sub! /^0+/, "" | |
# wenn Nummer Landesvorwahl enthaelt | |
if nr.size > 9 | |
# mit fuehrendem "00" ausgeben | |
puts "00" + nr | |
# sonst | |
else | |
# mit fuehrendem "0" ausgeben | |
puts "0" + nr | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0041791234567 | |
0041791234567 | |
0791234567 | |
0041791236790 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment