[Haskell-beginners] Question about Regular expression pattern consuming.
S. H. Aegis
shaegis at gmail.com
Mon Jul 29 15:15:35 CEST 2013
Wow! It's cool.
One more question, please...
In the DATA file, there is several 20[0-9]{13}AH201 strings.
How can I treat all of each pattern?
Thank you.
Sincirely, S. Chang.
2013/7/29 Julian Arni <julian at edx.org>
> 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
>>
>>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>
>
--
Sok Ha, CHANG
Dr. Chang's Clinic. #203. 503-23. AmSa-Dong, GangDong-Gu, Seoul.
Tel: +82-2-442-7585
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20130729/d44f1086/attachment.htm>
More information about the Beginners
mailing list