Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Question about Regular expression pattern    consuming.
      (Julian Arni)


----------------------------------------------------------------------

Message: 1
Date: Sun, 28 Jul 2013 22:50:52 -0400
From: Julian Arni <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Question about Regular expression
        pattern consuming.
Message-ID:
        <canct4crfsaxv8ecm9tvrfmomsd31qhntyfje6vj3zknszwg...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

splitRegex treats the regex as a delimiter, and does it fact "swallow" the
match. Use matchRegexAll instead - e.g.:

1 import Text.Regex
  2 import Control.Applicative
  3
  4 main :: IO()
  5 main = do
  6     myIn <- readFile "Data.dat"
  7     case (intoEachPt myIn) of
  8         Nothing -> print "No match"
  9         Just (a, b, c, d) -> do print a
 10                                 print b
 11                                 print c
 12
 13 intoEachPt :: String -> Maybe (String, String, String, [String])
 14 intoEachPt = matchRegexAll (mkRegex "20[0-9]{13}AH021")


On Sun, Jul 28, 2013 at 5:35 AM, S. H. Aegis <[email protected]> wrote:

> Hi.
> I'm newbie to Haskell.
> I want to get date, it's type is [[String]].
> The problem is that "the string that is used in regular expression
> pattern" is consumed. ie, disappear.
> Here is my code.
>
> ------------------------------------------------------------
> import Text.Regex
> import Control.Applicative
>
> main :: IO()
> main = do
>     myIn <- readFile "Data.dat"
>     print $ lines <$> intoEachPt myIn
>
> intoEachPt :: String -> [String]
> intoEachPt = splitRegex (mkRegex "20[0-9]{13}AH021")
> -----------------------------------------------------------
>
> How can I fix this?
>
>
> Data:
> ....there is many DIGIT.....201306000300001AH02112361640
> 9.......
>
> Output:
> [[....there is many DIGIT..."],["12361640             9......]....]
>
> I hope:
> [[....there is many DIGIT..."],["201306000300001AH02112361640
> 9......]....]
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130728/c327555f/attachment-0001.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 61, Issue 34
*****************************************

Reply via email to