The command could be called substitute (replace would have been nice, but it is already taken).
"foobar".substitute("...", "lum") -> "lumbar"
"foobar".substitute("(.).", lambda m: m['groups'][0]['str'], all=True) -> "foa"
This very common function would help fill in the lack of string manipulation functions.
I'd love this. I'm currently doing something like the following for simple find/replace type functions.
Search is inside split(' '). Replace is inside.add('+').
r('some long string with spaces').split(' ').reduce(
function(l, r){
return l.add('+').add(r)
}
)
Search is inside str.match('DO/NOT'). Replace is inside .append('REALLY').
r('some/string/that/i/DO/NOT/like/the/start/of').do(function (str){
return str.match('DO/NOT').default({end:0}).do(function (res){
return r.branch(
res('end').gt(0),
str.split('', res('end')).do(function(parts){
return parts.slice(0, res('start'))
.append('REALLY')
.union(parts.slice(res('end')))
.reduce(function(l, r){return l.add(r)})
}),
str
)
})
})
It would be great to replace that with something shorter.
@webmasterkai Those are pretty interesting work-arounds, thanks for sharing.
We'll hopefully get to this soon.
Most helpful comment
I'd love this. I'm currently doing something like the following for simple find/replace type functions.
Global Find Replace
Search is inside
split(' '). Replace is inside.add('+').Basic regex search/replace
Search is inside
str.match('DO/NOT'). Replace is inside.append('REALLY').It would be great to replace that with something shorter.