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.:
(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.)
brianMon 8 Aug 2011
Would it make more sense to have those be methods on Regex?
rfeldmanMon 8 Aug 2011
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).
kevinpenoMon 8 Aug 2011
I think it makes sense for Str.replace to accept Regex as the from argument. This would mimic how javascript's str.replace works.
peterWed 10 Aug 2011
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.
brianTue 15 Nov 2011
Promoted to ticket #1608 and assigned to brian
brianTue 15 Nov 2011
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.
peter Mon 8 Aug 2011
I would like to propose
sys:Str
gain two additional methods:replaceMatch
andreplaceMatches
. These would replace parts of a string based on a regular expression. e.g.:and parallel the existing:
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.)brian Mon 8 Aug 2011
Would it make more sense to have those be methods on Regex?
rfeldman Mon 8 Aug 2011
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).
kevinpeno Mon 8 Aug 2011
I think it makes sense for
Str.replace
to acceptRegex
as the from argument. This would mimic how javascript'sstr.replace
works.peter Wed 10 Aug 2011
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
andreplaceAll
though, for the names. I hadn't looked at the Java APIs for this.brian Tue 15 Nov 2011
Promoted to ticket #1608 and assigned to brian
brian Tue 15 Nov 2011
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.