I would like to propose sys:Str gain two additional methods: replaceMatch and replaceMatches. These would replace parts of a string based on a regular expression. e.g.:
"a1b2c3".replaceMatch (Regex <|\d|>, "-") => "a-b2c3"
"a1b2c3".replaceMatches(Regex <|\d|>, "-") => "a-b-c-"
and parallel the existing:
"a1b2c3".replace ("2", "-") => "a1b-c3"
What do people think?
(It seems sys::Str can only be extended using native methods - I can provide a Java version of these if needed. Currently, I have a Fantom implementation as static methods in a separate pod.)
Would it make more sense to have those be methods on Regex?
I will say it's been convenient on several occasions to use Java's .replaceFirst and .replaceAll equivalents on String (and as an aside, the Java names for those methods make more intuitive sense to me).
Brian, I don't mind if they are on Regex instead. It feels more natural to me to be Str, but either is fine.
I do prefer rfeldman's suggestion of replaceFirst and replaceAll though, for the names. I hadn't looked at the Java APIs for this.
Promoted to ticket #1608 and assigned to brian
Ticket resolved in 1.0.61
Given the current design, I decided not to mix Regex stuff directly into the Str class. But I did add replaceFirst and replaceAll methods on RegexMatcher.
Login or Signup to reply.