Login
|
Signup
langref.org
-
fsharp
,
erlang
,
clojure
, and
groovy
add..
all
cpp
csharp
fantom
go
haskell
java
ocaml
perl
php
python
ruby
scala
Home
All
Solved
Unsolved
Strings
Numbers
Regex
Lists
Maps
Structure
Files
Dates
OOP
Networking
XML
Algorithms
Misc
Parallel
View Problem
Regex
Matching
Check if a string matches with groups
Display
"two"
if
"one two three"
matches
/one (.*) three/
fsharp
let regmatch = (Regex.Match("one two three", "one (.*) three"))
if regmatch.Success then (printfn "%s" (regmatch.Groups.[1].Captures.[0].ToString()))
#light
open System
open System.Text.RegularExpressions
let regmatch = (Regex.Match("one two three", "one (.*) three"))
if regmatch.Success then (printfn "%s" (regmatch.Groups.[1].Captures.[0].ToString()))
erlang
12B3+
case re:run("one two three", "one (.*) three", [{capture, [1], list}]) of {match, Res} -> hd(Res) end.
case re:run("one two three", "one (.*) three", [{capture, [1], list}]) of {match, Res} -> hd(Res) end.
clojure
(if-let [groups (re-matches #"one (.*) three" "one two three")]
(println (second groups)))
(if-let [groups (re-matches #"one (.*) three" "one two three")]
(println (second groups)))
groovy
matcher = ("one two three" =~ /one (.*) three/)
if (matcher) println matcher[0][1]
matcher = ("one two three" =~ /one (.*) three/)
if (matcher) println matcher[0][1]
groovy
1.6.1+
match = "one two three".find("one (.*) three") { it[1] }
if (match) println match
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
...)