From: Martin DeMello Date: 2003-07-22T17:11:11+09:00 Subject: Re: Should String#strip take a parameter? Yukihiro Matsumoto wrote: > Hi, > > In message "Should String#strip take a parameter?" > on 03/07/22, "Warren Brown" writes: > > | If there is an interest in this, I can provide patches for 1.6.8 and/or > |the latest 1.8 snapshot. > > We need to define the behavior first. Python 2.3's strip takes a > parameter, but it strips off all characters in the string, i.e. > > a = "<><<>>>>><><>" > a.strip("<>") # => "abc" That's unintuitive, IMO. I think if strip takes a parameter, it should be a regex (a string can be autoconverted to its Regex.quoted form), and implicitly wrap the regex in a (...)*. e.g. s.strip(/[<>]/) -> s.gsub!(/^([<>])*/,'') s.gsub!(/([<>])*$/,'') whereas s.strip('<>') -> s.gsub!(/^(<>)*/,'') s.gsub!(/(<>)*$/,'') Treating a string as a character class is not convenient enough to justify its limitingness. (Do ruby regexes support a noncapturing, nonbacktracking form of ()*?) martin