View Problem
Loop through a string matching a regex and performing an action for each match
Create a list
Submit a new solution for ruby, clojure, erlang, or fsharp
There are 16 other solutions in additional languages (cpp, csharp, fantom, groovy ...)
[fish1,cow3,boat4] when matching "(fish):1 sausage (cow):3 tree (boat):4" with regex /\((\w+)\):(\d+)/
fsharp
let list = new ResizeArray<string>()
let mutable regmatch = (Regex.Match("(fish):1 sausage (cow):3 tree (boat):4", "\\((\\w+)\\):(\\d+)"))
while regmatch.Success do
list.Add(regmatch.Groups.[1].Captures.[0].ToString() ^ regmatch.Groups.[2].Captures.[0].ToString())
regmatch <- regmatch.NextMatch()
done
for word in list do printfn "%s" word done
let mutable regmatch = (Regex.Match("(fish):1 sausage (cow):3 tree (boat):4", "\\((\\w+)\\):(\\d+)"))
while regmatch.Success do
list.Add(regmatch.Groups.[1].Captures.[0].ToString() ^ regmatch.Groups.[2].Captures.[0].ToString())
regmatch <- regmatch.NextMatch()
done
for word in list do printfn "%s" word done
Submit a new solution for ruby, clojure, erlang, or fsharp
There are 16 other solutions in additional languages (cpp, csharp, fantom, groovy ...)




