https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112017-07-04T10:10:08ZRuby Issue Tracking SystemRuby master - Feature #13712: String#start_with? with regexphttps://redmine.ruby-lang.org/issues/13712?journal_id=656252017-07-04T10:10:08ZEregon (Benoit Daloze)
<ul></ul><p>Agreed, this would be great and intuitive.</p>
<p>I wonder, could the symmetrical String#end_with? also work with a Regexp? (having the same effect as a trailing \z in the Regexp)</p> Ruby master - Feature #13712: String#start_with? with regexphttps://redmine.ruby-lang.org/issues/13712?journal_id=656282017-07-04T14:43:38Zshevegen (Robert A. Heiler)shevegen@gmail.com
<ul></ul><p>I agree as well, would be nice. More than one way to do things. Should also be the same for .start_with? and .end_with?</p> Ruby master - Feature #13712: String#start_with? with regexphttps://redmine.ruby-lang.org/issues/13712?journal_id=656332017-07-05T00:30:22Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul></ul><p>+1 for start_with? but I have no practical usage of end_with? so a bit negative about that part. Do people really need regexp version of .end_with?</p> Ruby master - Feature #13712: String#start_with? with regexphttps://redmine.ruby-lang.org/issues/13712?journal_id=656352017-07-05T02:33:10Zphluid61 (Matthew Kerwin)matthew@kerwin.net.au
<ul></ul><p>shyouhei (Shyouhei Urabe) wrote:</p>
<blockquote>
<p>+1 for start_with? but I have no practical usage of end_with? so a bit negative about that part. Do people really need regexp version of .end_with?</p>
</blockquote>
<p>I've used regexen at different times to match final punctuation (e.g. <code>/\?[!.]*/</code>) and trailing whitespace (e.g. <code>/\s/</code>). I think it's more readable having <code>str.end_with? /pattern/</code> instead of <code>str =~ /pattern\z/</code></p> Ruby master - Feature #13712: String#start_with? with regexphttps://redmine.ruby-lang.org/issues/13712?journal_id=656362017-07-05T02:46:25Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul></ul><p>phluid61 (Matthew Kerwin) wrote:</p>
<blockquote>
<p>I've used regexen at different times to match final punctuation (e.g. <code>/\?[!.]*/</code>) and trailing whitespace (e.g. <code>/\s/</code>). I think it's more readable having <code>str.end_with? /pattern/</code> instead of <code>str =~ /pattern\z/</code></p>
</blockquote>
<p>I see. Thank you.</p> Ruby master - Feature #13712: String#start_with? with regexphttps://redmine.ruby-lang.org/issues/13712?journal_id=656372017-07-05T03:50:23Zduerst (Martin Dürst)duerst@it.aoyama.ac.jp
<ul></ul><p>shyouhei (Shyouhei Urabe) wrote:</p>
<blockquote>
<p>+1 for start_with? but I have no practical usage of end_with? so a bit negative about that part. Do people really need regexp version of .end_with?</p>
</blockquote>
<p>In addition, even if we don't have a direct use case, it's very easy for somebody to try out, and then send a bug report here if it's not available. I know we don't add functionality just because "somebody eventually may need it", but in this case, it seems to be justified to streamline things.</p> Ruby master - Feature #13712: String#start_with? with regexphttps://redmine.ruby-lang.org/issues/13712?journal_id=656382017-07-05T05:27:12Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><p>Will you need <code>$~</code> after <code>start_with?(re)</code>?</p> Ruby master - Feature #13712: String#start_with? with regexphttps://redmine.ruby-lang.org/issues/13712?journal_id=656392017-07-05T06:01:52Zphluid61 (Matthew Kerwin)matthew@kerwin.net.au
<ul></ul><p>nobu (Nobuyoshi Nakada) wrote:</p>
<blockquote>
<p>Will you need <code>$~</code> after <code>start_with?(re)</code>?</p>
</blockquote>
<p>Personally, I don't see that I'll ever need it. If people do want it, they can lodge a feature request in future?</p> Ruby master - Feature #13712: String#start_with? with regexphttps://redmine.ruby-lang.org/issues/13712?journal_id=656422017-07-05T09:35:56ZEregon (Benoit Daloze)
<ul></ul><p>nobu (Nobuyoshi Nakada) wrote:</p>
<blockquote>
<p>Will you need <code>$~</code> after <code>start_with?(re)</code>?</p>
</blockquote>
<p>It might be quite useful when parsing, to avoid doing a second match just to get captures.</p> Ruby master - Feature #13712: String#start_with? with regexphttps://redmine.ruby-lang.org/issues/13712?journal_id=656432017-07-05T10:11:17Zphluid61 (Matthew Kerwin)matthew@kerwin.net.au
<ul></ul><p>Eregon (Benoit Daloze) wrote:</p>
<blockquote>
<p>It might be quite useful when parsing, to avoid doing a second match just to get captures.</p>
</blockquote>
<p>That could depend on whether <code>$&</code>, <code>$1</code>, <code>$2</code>, etc. are set. I assumed <a class="user active user-mention" href="https://redmine.ruby-lang.org/users/4">@nobu (Nobuyoshi Nakada)</a> was only asking about <code>$~</code> because allocating a whole MatchData object is heavier than just allocating some strings.</p> Ruby master - Feature #13712: String#start_with? with regexphttps://redmine.ruby-lang.org/issues/13712?journal_id=656462017-07-05T11:44:41ZEregon (Benoit Daloze)
<ul></ul><p>phluid61 (Matthew Kerwin) wrote:</p>
<blockquote>
<p>That could depend on whether <code>$&</code>, <code>$1</code>, <code>$2</code>, etc. are set. I assumed <a class="user active user-mention" href="https://redmine.ruby-lang.org/users/4">@nobu (Nobuyoshi Nakada)</a> was only asking about <code>$~</code> because allocating a whole MatchData object is heavier than just allocating some strings.</p>
</blockquote>
<p>$&, $1, etc always just read from $~, so it's the same thing.</p> Ruby master - Feature #13712: String#start_with? with regexphttps://redmine.ruby-lang.org/issues/13712?journal_id=657162017-07-10T02:24:23Zshevegen (Robert A. Heiler)shevegen@gmail.com
<ul></ul><p>Shyouhei Urabe) wrote:</p>
<blockquote>
<p>+1 for start_with? but I have no practical usage of end_with? so a bit negative about<br>
that part. Do people really need regexp version of .end_with?</p>
</blockquote>
<p>I do not know if the use case frequency is the same. Perhaps you are right that anchoring<br>
or .start_with? is more frequent than .end_with?, via regexes.</p>
<p>But I think that, even when there is a much smaller use case for .end_with? (let's just<br>
assume it for the moment), I think that both .start_with? and .end_with? should behave<br>
the same. Otherwise people may then ask "why does .start_with? allow regex input but<br>
.end_with? does not?". :)</p>
<p>I think it may be useful though?</p>
<pre><code>x = 'abc def'
puts 'yep, ends with either e or f' if x.end_with? /e|f/
</code></pre>
<p>At the least to me it seems to be mostly symmetrical use cases, even if one may<br>
be more prevalent than the others. I guess the point may be that it just gives people<br>
more flexibility - in these cases, if they would rather want to use a regexp than<br>
a string, they can do so.</p> Ruby master - Feature #13712: String#start_with? with regexphttps://redmine.ruby-lang.org/issues/13712?journal_id=673442017-10-19T07:54:21Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p>Agreed. Need to update <code>Regexp.last_math</code>.</p>
<p>Matz.</p> Ruby master - Feature #13712: String#start_with? with regexphttps://redmine.ruby-lang.org/issues/13712?journal_id=673972017-10-21T06:51:13Znaruse (Yui NARUSE)naruse@airemix.jp
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Applied in changeset trunk|r60234.</p>
<hr>
<p>[Feature <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: String#start_with? with regexp (Closed)" href="https://redmine.ruby-lang.org/issues/13712">#13712</a>] String#start_with? supports regexp</p> Ruby master - Feature #13712: String#start_with? with regexphttps://redmine.ruby-lang.org/issues/13712?journal_id=679302017-11-27T10:48:29Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Related to</strong> <i><a class="issue tracker-2 status-7 priority-4 priority-default closed" href="/issues/3388">Feature #3388</a>: regexp support for start_with? and end_with?</i> added</li></ul>