掃碼下載編程獅APP
#!/usr/bin/ruby # -*- coding: UTF-8 -*- phone = "138-3453-1111 #這是一個(gè)電話號碼" # 刪除 Ruby 的注釋 phone = phone.sub!(/#.*$/, ") puts "電話號碼 : #{phone}" # 移除數(shù)字以外的其他字符 phone = phone.gsub!(/D/, ") puts "電話號碼 : #{phone}"