https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112020-08-13T17:10:49ZRuby Issue Tracking SystemRuby master - Bug #17120: String#start_with? return wrong result for Regexp patterns containing /\K/https://bugs.ruby-lang.org/issues/17120?journal_id=870532020-08-13T17:10:49Zhanazuki (Kasumi Hanazuki)
<ul></ul><p>Patch: <a href="https://github.com/ruby/ruby/pull/3417" class="external">https://github.com/ruby/ruby/pull/3417</a></p> Ruby master - Bug #17120: String#start_with? return wrong result for Regexp patterns containing /\K/https://bugs.ruby-lang.org/issues/17120?journal_id=980732022-06-17T09:17:59Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul><p><code>\K</code> changes the start position of the match string, but it does not change the match position itself. Actually, <code>"hello" =~ /h\Ke/</code> returns 0. (Note that <code>Regexp#=~</code> return the start position of the match.)</p>
<pre><code>irb(main):001:0> "hello" =~ /h\Ke/
=> 0
irb(main):002:0> $~.begin(0)
=> 1
</code></pre>
<p>So I think this is by design.</p>