From: "sawa (Tsuyoshi Sawada) via ruby-core" Date: 2023-01-19T12:17:33+00:00 Subject: [ruby-core:111905] [Ruby master Feature#12698] Method to delete a substring by regex match Issue #12698 has been updated by sawa (Tsuyoshi Sawada). I now agree with https://bugs.ruby-lang.org/issues/12698#note-9. This issue can be considered to be along that line. ---------------------------------------- Feature #12698: Method to delete a substring by regex match https://bugs.ruby-lang.org/issues/12698#change-101326 * Author: sawa (Tsuyoshi Sawada) * Status: Feedback * Priority: Normal ---------------------------------------- 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/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/