Login
|
Signup
langref.org
-
python
,
erlang
, and
clojure
add..
all
cpp
csharp
fantom
fsharp
go
groovy
haskell
java
ocaml
perl
php
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/
python
match = re.match(r'one (.*) three', 'one two three')
if match:
print match.group(1)
match = re.match(r'one (.*) three', 'one two three')
if match:
print match.group(1)
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)))
Submit a new solution for
python
,
erlang
, or
clojure
There are 16 other solutions in
additional
languages (
cpp
,
csharp
,
fantom
,
fsharp
...)