View Problem

Check if a string matches with groups

Display "two" if "one two three" matches /one (.*) three/
DiskEdit
python
match = re.match(r'one (.*) three', 'one two three')
if match:
print match.group(1)
ExpandDiskEdit
fsharp
let regmatch = (Regex.Match("one two three", "one (.*) three"))
if regmatch.Success then (printfn "%s" (regmatch.Groups.[1].Captures.[0].ToString()))
ExpandDiskEdit
cpp C++/CLI .NET 2.0
Match^ match = Regex::Match("one two three", "one (.*) three");
if (match->Success) Console::WriteLine("{0}", match->Groups[1]->Captures[0]);
ExpandDiskEdit
cpp
cmatch what;
if (regex_match("one two three", what, regex("one (.*) three")))
cout << what[1] << endl;

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