From: shevegen@... Date: 2016-08-27T19:14:15+00:00 Subject: [ruby-core:77084] [Ruby trunk Feature#12698] Method to delete a substring by regex match Issue #12698 has been updated by Robert A. Heiler. I assume that this makes sense; my only concern is that ruby people may be confused as to what to use. We have lots of ways :) .gsub .sub .delete .tr [] = Actually, I think my biggest complaint is that .delete() would sound so similar to .remove() - .delete(/regex_here/) might be nice too. But anyway, to conclude, I concur with the threadstarter in principle, I think that ruby should know what to do when either a string is given as argument or a regex so I am in principle in favour of the suggestion. ---------------------------------------- Feature #12698: Method to delete a substring by regex match https://bugs.ruby-lang.org/issues/12698#change-60306 * Author: Tsuyoshi Sawada * Status: Open * Priority: Normal * Assignee: ---------------------------------------- There is frequent need to delete a substring from a string. There already are methods `String#delete` and `String#delete!`, but their feature is a little bit different from the use cases that I am mentioning here. I request methods that take a string or a regexp as an argument, and delete the matches from the receiver string. I am not sure of the method name, and I will use the term `remove` here. It can be named in some other better way. I request all combinations of global vs. local, and non-destructive vs. destructive. The expected feature is something like the following. First, the non-destructive ones: ```ruby "abcabc".remove("c") # => "ababc" "abcabc".remove(/\zc/) # => "abcab" "abcabc".gremove("c") # => "abab" "abcabc".gremove(/c/) # => "abab" ``` Then, the destructive ones: ```ruby s = "abcabc" s.remove!("c") # => "ababc" s # => "ababc" s = "abcabc" s.gremove!("d") # => nil s # => "abcabc" ``` Using this, cases like https://bugs.ruby-lang.org/issues/12694 would be just special cases. They can be handled like this: ```ruby "abcdef".remove(/\Aabc/) # => "def" -- https://bugs.ruby-lang.org/ Unsubscribe: