Support maximum repetition count
Consider the regex \d{,6}. I'd like this library to contain a function replicateAlt that lets me implement this regex as replicateAlt 6 digit. One possible implementation would be a duplicate of replicateM, but with <|> pure [] on the end of the recursive case.
If you like this idea, I can PR it, but I'm not sure which module you want it in.
Does this do what you want?
I'd accept a PR explaining (in the haddocks) how to do this for others who may be looking for the same thing.
Yes, that's what I need for now. Although it looks like they only have a greedy one, so if I instead needed the non-greedy \d{,6}?, I'd be right back to needing to roll my own.
Ah, good point. In that case it may be worth defining our own function.
I dropped in intending to ask this in a separate issue, but this seems like a good spot:
What is the best way to quantify numerically? I know you can cobble something together out of what's already there. For instance, to match exactly n digits I can do
ghci> dig :: RE Char String; dig = pure <$> psym isDigit
ghci> <string> =~ (foldr1 (<>) $ replicate n dig)
But is this more or less it? Or is there some count-style combinator already built in, that I'm missing in the docs?
Have you seen the count combinator linked above?
Have you seen the
countcombinator linked above?
My apologies: I did see it, but did not understand the context..
I hadn't realized it applies to all instances of alternative. I thought it was more like the count I linked to, which was specific to ReadP.
Thank you!