MST

星途 面试题库

面试题:Ruby正则表达式之基础替换

在Ruby中,给定字符串'hello world',使用正则表达式将所有的'l'替换为'x',请写出实现代码。
43.3万 热度难度
编程语言Ruby

知识考点

AI 面试

面试题答案

一键面试
str = 'hello world'
new_str = str.gsub(/l/, 'x')
puts new_str