更新时间:2023-02-23 09:29:07
s = s.sub(/^https?\:\/\//, '').sub(/^www./,'')
如果你不想使用 s =
,你应该使用 sub!
s 而不是所有的 sub
s.
If you don't want to use s =
, you should use sub!
s instead of all sub
s.
您的代码存在的问题是:
The problems with your code are:
sub
而不是 gsub
和 ^
所以它只替换 http://代码> 在开头,但将代码留在中间.
sub
instead of gsub
and ^
in the beginning of Regexp so it only replaces the http://
in the beginning but leaves the ones in the middle.