regex-applicative
regex-applicative copied to clipboard
Document matching end of line
I couldn't find an example on how I match [0-9]+[.][0-9][0-9]$ - that is, match something at the end of a line.
Use the function to match the whole line, and include the equivalent of .* at the beginning of the pattern.
Not sure if this is a good idea, as it isn't very composable.
Say I want to match "(foo($| )|bar)" then now I have to rewrite it to
"(foo ?|bar.*)" that last expression is no longer composable as the first one was.
Well, it is the way at the moment.
I don't have the resources to investigate whether and how this can be implemented, but you can look into it yourself if you wish.
I wanted to remove 'index.html' from string. I found out that the following code was working:
stripIndex :: String -> String
stripIndex = takeWhile (/= '\0') .
replace ((:) <$> sym '/'
<* string "index.html"
<*> (concat <$> many query)
<* sym '\0') .
(++ "\0")
where
isDelim = (`elem` ['/', '#', '?'])
query = (:) <$> (sym '#' <|> sym '?') <*> many (psym $ not . isDelim)
By generalizing this, can we solve this issue?
@demokritos why do this instead of https://github.com/feuerbach/regex-applicative/issues/30#issuecomment-182798229?
Did you mean this?
stripIndex :: String -> String
stripIndex str = fromMaybe str $
match ((\a b c -> a ++ b : c) <$> many anySym
<*> sym '/'
<* string "index.html"
<*> (concat <$> many query)) str
where
query = (:) <$> (sym '#' <|> sym '?') <*> many (psym (/= '/'))
I didn't know that match can replace.
I wonder whether the syntax below is possible by introducing special boundary indicators.
stripIndex = replace ((:) <$> sym '/'
<* string "index.html"
<*> (concat <$> many query)
<* EndOfLine)
Thanks.
Yeah, I think it could be possible.
My answer is the same as 4 years ago (wow, time flies!): I'd consider a carefully motivated and implemented pull request, but I don't have the resources to look into this myself.