Question about Regular expression pattern consuming.

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......]....]

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
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@haskell.org http://www.haskell.org/mailman/listinfo/beginners

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
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
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@haskell.org http://www.haskell.org/mailman/listinfo/beginners
_______________________________________________ Beginners mailing list Beginners@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
participants (2)
-
Julian Arni
-
S. H. Aegis