How can I use parsec to parse all matching input in a string and discard the rest?
Example: I have a simple number parser, and I can find all numbers if I know what separates them:
num :: Parser Int num = read <$> many digit parse (num `sepBy` space) "" "111 4 22"
But what if I donโt know what is between the numbers?
"I will live to be 111 years <b>old</b> if I work out 4 days a week starting at 22."
many anyChar does not work as a delimiter because it consumes everything.
So how can I get things that correspond to an arbitrary parser surrounded by things that I want to ignore?
EDIT . Note that in a real task, my parser is more complex:
optionTag :: Parser Fragment optionTag = do string "<option" manyTill anyChar (string "value=") n <- many1 digit manyTill anyChar (char '>') chapterPrefix text <- many1 (noneOf "<>") return $ Option (read n) text where chapterPrefix = many digit >> char '.' >> many space
source share