[Haskell-beginners] Question about Regular expression pattern consuming.
Julian Arni
julian at edx.org
Mon Jul 29 04:50:52 CEST 2013
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 <shaegis at gmail.com> 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
> Beginners at haskell.org
> 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.htm>
More information about the Beginners
mailing list