Login
|
Signup
langref.org
-
ruby
,
clojure
,
erlang
, and
fsharp
add..
all
cpp
csharp
fantom
go
groovy
haskell
java
ocaml
perl
php
python
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/
ruby
puts $1 if "one two three"=~/^one (.*) three$/
puts $1 if "one two three"=~/^one (.*) three$/
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)))
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.
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()))
Submit a new solution for
ruby
,
clojure
,
erlang
, or
fsharp
There are 15 other solutions in
additional
languages (
cpp
,
csharp
,
fantom
,
go
...)