From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: AS4713 221.184.0.0/13 X-Spam-Status: No, score=-3.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_MED,SPF_PASS,T_DKIM_INVALID, T_RP_MATCHES_RCVD shortcircuit=no autolearn=ham autolearn_force=no version=3.4.0 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 468071FD09 for ; Wed, 31 May 2017 12:37:51 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 39130120739; Wed, 31 May 2017 21:37:49 +0900 (JST) Received: from o1678948x4.outbound-mail.sendgrid.net (o1678948x4.outbound-mail.sendgrid.net [167.89.48.4]) by neon.ruby-lang.org (Postfix) with ESMTPS id 81B0B120736 for ; Wed, 31 May 2017 21:37:46 +0900 (JST) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=sendgrid.me; h=from:to:references:subject:mime-version:content-type:content-transfer-encoding:list-id; s=smtpapi; bh=451PrFapVDZTcftbu5tH+RbFqb4=; b=pafkE3VpFf2BYQkjFW d0ZzkvmxqRzzw0zQ2G0A3OexH2duS5SAbo9PdP+WTytVgOiC7kQs5wmE5wQ3349O AG8YFoJ16zOBWh6vFHqq6u2E20m0zsgY6MRl+VxVg73ZVClE2xhhOdayS2DLv5ry eG8/Ac9pWke8hOP3QAKLkpLi4= Received: by filter1113p1mdw1.sendgrid.net with SMTP id filter1113p1mdw1-26228-592EB913-38 2017-05-31 12:37:39.412661431 +0000 UTC Received: from herokuapp.com (ec2-54-163-144-241.compute-1.amazonaws.com [54.163.144.241]) by ismtpd0005p1iad1.sendgrid.net (SG) with ESMTP id Ku-CyRMYTo2KXaOy9L8sSQ for ; Wed, 31 May 2017 12:37:39.337 +0000 (UTC) Date: Wed, 31 May 2017 12:37:39 +0000 From: zn@mbf.nifty.com To: ruby-core@ruby-lang.org Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 56516 X-Redmine-Project: ruby-trunk X-Redmine-Issue-Id: 12694 X-Redmine-Issue-Author: sonots X-Redmine-Sender: znz X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: ync6xU2WACa70kv/Ymy4QrNMhiuLXJG8OTL2vJD1yS7XC1Umdm9UiMgcUkuKeEniJHePjz1y5cGzXE p8nn8VOdIrMnOYRZ/tdlR6dR3ZeFuH1gxihEZHqYiKIRTNRs/QElKKmggNpnrcU9aFAcdUOxa6BP2j pzfd+5h8ZF5VuSRxR9sqo5+nJHw4oJkl3/sGwb/8PeUYmSsEOYR3meU9Mg== X-ML-Name: ruby-core X-Mail-Count: 81486 Subject: [ruby-core:81486] [Ruby trunk Feature#12694] Want a String method to remove heading substr X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #12694 has been updated by znz (Kazuhiro NISHIYAMA). > `str.sub(/^#{Regexp.escape(substr)}/, '') #=> 'def'` I think `^` should be `\A` in description of this ticket. (and maybe in handle_tag_name_mixin.rb of fluentd too) Which is expected?: first prefix of string only or prefix of each line ---------------------------------------- Feature #12694: Want a String method to remove heading substr https://bugs.ruby-lang.org/issues/12694#change-65195 * Author: sonots (Naotoshi Seo) * Status: Open * Priority: Normal * Assignee: * Target version: ---------------------------------------- I often write codes like: ```ruby str = 'abcdef' substr = 'abc' str[substr.size..-1] if str.start_with?(substr) #=> 'def' # or str.sub(/^#{Regexp.escape(substr)}/, '') #=> 'def' ``` I want a short hand which is something like: ```ruby str = 'abcdef' substr = 'abc' str.lstrip(substr) #=> 'def' ``` Having similar argument for `String#rstrip` would be nice for symmetry although we already have `String#chomp(substr)` My frequent use-case is coming from fluentd. We have `remove_tag_prefix` option to remove a heading substring from a tag. We currently using `String#sub` with a regular expression, but I feel regular expression matching is too much just to remove a heading substring. https://github.com/fluent/fluentd/blob/75005f18d48ed3d416890413fa5f83982b264c71/lib/fluent/compat/handle_tag_name_mixin.rb#L45 -- https://bugs.ruby-lang.org/