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 byd
,instead of a digit.