View Problem

Check if a string matches with groups

Display "two" if "one two three" matches /one (.*) three/
ExpandDiskEdit
fsharp
let regmatch = (Regex.Match("one two three", "one (.*) three"))
if regmatch.Success then (printfn "%s" (regmatch.Groups.[1].Captures.[0].ToString()))
DiskEdit
erlang 12B3+
case re:run("one two three", "one (.*) three", [{capture, [1], list}]) of {match, Res} -> hd(Res) end.
DiskEdit
clojure
(if-let [groups (re-matches #"one (.*) three" "one two three")]
(println (second groups)))
DiskEdit
groovy
matcher = ("one two three" =~ /one (.*) three/)
if (matcher) println matcher[0][1]
DiskEdit
groovy 1.6.1+
match = "one two three".find("one (.*) three") { it[1] }
if (match) println match

Submit a new solution for fsharp, erlang, clojure, or groovy
There are 14 other solutions in additional languages (cpp, csharp, fantom, go ...)