ruby code example(9)

ruby code example(9)
line = "abc"
if line =~ /Perl|Python/ ##匹配正则表达式
puts "Scripting language mentioned: #{line}"
end


line.sub(/Perl/, 'Ruby') # replace first 'Perl' with 'Ruby'
line.gsub(/Python/, 'Ruby') # replace every 'Python' with 'Ruby'

你可能感兴趣的:(ruby code example(9))