Text.Regex.matchRegex: Success is empty?

Esteemed Haskellers, It is working for me, but I am puzzled by the matchRegex function: > import Text.Regex > :i matchRegex matchRegex :: Regex -> String -> Maybe [String] -- Defined in ‘Text.Regex’ Searches that fail return Nothing: > matchRegex (mkRegex "z") "abracadabra" Nothing which makes sense. But why do searches that succeed return an empty list of Strings? > matchRegex (mkRegex "a") "abracadabra" Just [] > -- Jeffrey Benjamin Brown

Hi Jeffrey, It returns ‘Just’, because the pattern was found. The list is empty, because no capture groups are defined in the regex. matchRegex (mkRegex “(a)”) “abracadabra" returns Just [“a”] Csongor
On 5 Apr 2016, at 22:16, Jeffrey Brown
wrote: Esteemed Haskellers,
It is working for me, but I am puzzled by the matchRegex function:
> import Text.Regex > :i matchRegex matchRegex :: Regex -> String -> Maybe [String] -- Defined in ‘Text.Regex’
Searches that fail return Nothing:
> matchRegex (mkRegex "z") "abracadabra" Nothing
which makes sense. But why do searches that succeed return an empty list of Strings?
> matchRegex (mkRegex "a") "abracadabra" Just [] >
-- Jeffrey Benjamin Brown _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

The regex-compat docs say "
Returns:
https://hackage.haskell.org/packages/archive/base/4.5.0.0/doc/html/Data-Mayb...
strs
if the match succeeded (and
strs
is the list of subexpression matches), or
https://hackage.haskell.org/packages/archive/base/4.5.0.0/doc/html/Data-Mayb...
otherwise.
”
.
Adam Bergmark
On Tue 05 Apr 2016 at 22:16 Jeffrey Brown
<
mailto:Jeffrey Brown
wrote:
Esteemed Haskellers, It is working for me, but I am puzzled by the matchRegex function: > import Text.Regex > :i matchRegex matchRegex :: Regex -> String -> Maybe [String] -- Defined in ‘Text.Regex’ Searches that fail return Nothing: > matchRegex (mkRegex "z") "abracadabra" Nothing which makes sense. But why do searches that succeed return an empty list of Strings? > matchRegex (mkRegex "a") "abracadabra" Just [] > -- Jeffrey Benjamin Brown _______________________________________________ Haskell-Cafe mailing list mailto:Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe

Aha! Thanks, Kiss!
On Tue, Apr 5, 2016 at 1:24 PM, Adam Bergmark
The regex-compat docs say "Returns: Just https://hackage.haskell.org/packages/archive/base/4.5.0.0/doc/html/Data-Mayb... strs if the match succeeded (and strs is the list of subexpression matches), or Nothing https://hackage.haskell.org/packages/archive/base/4.5.0.0/doc/html/Data-Mayb... otherwise.”.
Adam Bergmark
On Tue 05 Apr 2016 at 22:16 Jeffrey Brown
> wrote: Esteemed Haskellers,
It is working for me, but I am puzzled by the matchRegex function:
> import Text.Regex > :i matchRegex matchRegex :: Regex -> String -> Maybe [String] -- Defined in ‘Text.Regex’
Searches that fail return Nothing:
> matchRegex (mkRegex "z") "abracadabra" Nothing
which makes sense. But why do searches that succeed return an empty list of Strings?
> matchRegex (mkRegex "a") "abracadabra" Just [] >
-- Jeffrey Benjamin Brown
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
-- Jeffrey Benjamin Brown
participants (3)
-
Adam Bergmark
-
Jeffrey Brown
-
Kiss Csongor