import Data.Char main = do putStrLn $ decode "W4E2H3" putStrLn $ decode "A12T3Y4" decode :: String -> String decode = concat . map expand . split expand :: String -> String expand "" = "" expand (x:xs) = take (read xs) $ repeat x split :: String -> [String] split = words . tail . foldr fn "" where fn x acc = if (ord x < 48 || ord x > 57) then (' ':x:acc) else (x:acc)