View Problem

Replace the first regex match in a string with a static string

Transform "Red Green Blue" into "R*d Green Blue" by replacing /e/ with "*"
DiskEdit
ruby
p "Red Green Blue".sub(/e/,'*')
DiskEdit
clojure
(.replaceFirst (re-matcher #"e" "Red Green Blue") "*")
ExpandDiskEdit
cpp C++/CLI .NET 2.0
String^ Replaced = (gcnew Regex("e"))->Replace("Red Green Blue", "*", 1);
ExpandDiskEdit
fantom
replaced := Regex<|e|>.split("Red Green Blue",2).join("*")
ExpandDiskEdit
go
i := 0
f := func (in string) (out string) {
i++
if i == 1 {
return "*"
}
return in
}

re, _ := regexp.Compile("e")
s := re.ReplaceAllStringFunc("Red Green Blue", f)
fmt.Println(s)

Submit a new solution for ruby, csharp, clojure, cpp ...
There are 10 other solutions in additional languages (erlang, fsharp, groovy, java ...)