简单教程
提交运行
代码编辑器:
# !/usr/bin/ruby -w # -*- encoding:utf-8 -*- # filename: main.rb # author: 简单教程(www.twle.cn) # Copyright © 2015-2065 www.twle.cn. All rights reserved. phone = "138-3453-1111 #这是一个电话号码" # 删除 Ruby 的注释 phone = phone.sub!(/#.*$/, "") puts "电话号码 : #{phone}" # 移除数字以外的其他字符 phone = phone.gsub!(/\D/, "") puts "电话号码 : #{phone}"
运行结果: