加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

如何用ruby替换模式的每个实例?

发布时间:2020-12-16 20:09:29 所属栏目:百科 来源:网络整理
导读:string.sub看起来只会替换第一个实例.是否有可替代所有模式的方法或另一种方法?你可以在像Perl这样的正则表达式中执行它吗? (我觉得像r / blah / blah /) …和1给任何人谁可以告诉我为什么在地球上string.sub替换只是第一场比赛? 解决方法 String.gsub应
string.sub看起来只会替换第一个实例.是否有可替代所有模式的方法或另一种方法?你可以在像Perl这样的正则表达式中执行它吗?

(我觉得像r / blah / blah /)

…和1给任何人谁可以告诉我为什么在地球上string.sub替换只是第一场比赛?

解决方法

String.gsub应该做的伎俩

引用文件:

gsub(pattern,replacement) → new_str

Returns a copy of str with the all occurrences of pattern
substituted for the second argument. The pattern is typically a
Regexp; if given as a String,any regular expression metacharacters it
contains will be interpreted literally,e.g. d will match a
backlash followed by d,instead of a digit.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读