Issue #21552 has been updated by Eregon (Benoit Daloze). Eregon (Benoit Daloze) wrote in #note-9:
but that sounds more like something that could/should be optimized in the regexp engine
To substantiate that: ``` $ ruby -rbenchmark/ips -e 'SPACES = ["\0", *("\t".."\r"), " "].join; TARGET = SPACES + "x" * 1024 + SPACES; r=nil; Benchmark.ips { _1.report { r = TARGET.sub(/[\0\s]+\z/, "") } }' ruby 3.4.7 (2025-10-08 revision 7a5688e2a2) +PRISM [x86_64-linux] Warming up -------------------------------------- 7.106k i/100ms Calculating ------------------------------------- 71.778k (± 1.8%) i/s (13.93 μs/i) - 362.406k in 5.050632s $ ruby -rbenchmark/ips -e 'SPACES = ["\0", *("\t".."\r"), " "].join; TARGET = SPACES + "x" * 1024 + SPACES; r=nil; Benchmark.ips { _1.report { r = TARGET.sub(/[\0\s]+\z/, "") } }' truffleruby 33.0.0-dev-bb226b84 (2025-12-01), like ruby 3.3.7, Oracle GraalVM Native [x86_64-linux] Warming up -------------------------------------- 475.108k i/100ms Calculating ------------------------------------- 25.222M (± 4.5%) i/s (39.65 ns/i) - 125.904M in 5.008875s ``` ---------------------------------------- Feature #21552: allow String.strip and similar to take a parameter similar to String.delete https://bugs.ruby-lang.org/issues/21552#change-115577 * Author: MSP-Greg (Greg L) * Status: Open ---------------------------------------- Regrading `String.strip` (and `lstrip`, `rstrip`, and `!` versions) Some text data representations differentiate between what one might call vertical and horizontal white space, and the 'strip' methods currently strip both. It would be helpful if they had an optional parameter similar to `String.delete` with a one multi-character selector, so one could do: ```ruby t = str.strip " \t" ``` One can use a regex for this, but this much simpler. -- https://bugs.ruby-lang.org/