Project

General

Profile

Actions

Backport #8856

closed

gsub doesn't work properly with \K

Added by k_takata (Ken Takata) over 11 years ago. Updated over 11 years ago.


Description

Regexp#gsub で \K を使うと、正しく動作しないようです。
Regexp#sub は問題ありません。

http://rubyist.g.hatena.ne.jp/n2s/20130714/p1 より、

% irb-ruby-2.0.0-p247
2.0.0p247 :001 > a="foobarbazquux/foobarbazquux"
=> "foobarbazquux/foobarbazquux"
2.0.0p247 :002 > a.sub(/foo\Kbar/, "")
=> "foobazquux/foobarbazquux"
2.0.0p247 :003 > a.gsub(/foo\Kbar/, "")
=> "bazquux/bazquux"

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0