Forum: Ruby-dev [ruby-trunk - Bug #8856][Open] gsub doesn't work properly with \K

C4e88907313843cf07f6d85ba8162120?d=identicon&s=25 k_takata (Ken Takata) (Guest)
on 2013-09-03 15:42
(Received via mailing list)
Issue #8856 has been reported by k_takata (Ken Takata).

----------------------------------------
Bug #8856: gsub doesn't work properly with \K
https://bugs.ruby-lang.org/issues/8856

Author: k_takata (Ken Takata)
Status: Open
Priority: Normal
Assignee:
Category: regexp
Target version:
ruby -v: 2.0.0p247
Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN


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"
F1d6cc2b735bfd82c8773172da2aeab9?d=identicon&s=25 Nobuyoshi Nakada (nobu)
on 2013-09-04 03:24
(Received via mailing list)
Issue #8856 has been updated by nobu (Nobuyoshi Nakada).

Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN to 1.9.3: DONTNEED,
2.0.0: REQUIRED


----------------------------------------
Bug #8856: gsub doesn't work properly with \K
https://bugs.ruby-lang.org/issues/8856#change-41591

Author: k_takata (Ken Takata)
Status: Open
Priority: Normal
Assignee:
Category: regexp
Target version:
ruby -v: 2.0.0p247
Backport: 1.9.3: DONTNEED, 2.0.0: REQUIRED


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"
This topic is locked and can not be replied to.