haskell-hvr / regex-tdfa

Pure Haskell Tagged DFA Backend for "Text.Regex" (regex-base)
http://hackage.haskell.org/package/regex-tdfa
Other
36 stars 9 forks source link

No way to efficiently match at beginning of string? #12

Open raxod502 opened 4 years ago

raxod502 commented 4 years ago

I have a long string and need to check if a regex matches at the beginning of it (I am writing a lexer). Unfortunately, regex-tdfa does not appear to stop searching once it is clear that there is no match. For example, the following code snippet takes several seconds to evaluate on my machine:

Text.Regex.TDFA> replicate 100000000 'f' =~~ "\\`g" :: Maybe String
Nothing

However, the code snippet should evaluate instantly, because as soon as the first character is inspected it is clear that the regex does not match at the beginning of the string. Given this behavior, it seems impossible to use regex-tdfa to performantly match a regex at the beginning of a string. Is there a special-purpose function for this that I have missed?