3 ms·
Not the point of the article, but the slow-down from using regular expressions can be avoided in this case by instead generating each case permutation and searc
by boyter 6y ago
Not the point of the article, but the slow-down from using regular expressions can be avoided in this case by instead generating each case permutation and searching on that. Although its actually a bit more complex because you need to cut off doing this for long strings to avoid too many permutations but you get the idea.
Posting just in case someone thinks they need to build an index in order to case-insensitive search a few gigabytes of text. Its actually how tools like ripgrep tend to work (assuming it can do literal extraction of the regular expression). The moment you get to 10's of gigabytes though an index is probably what you need.
I actually have some Go code (since the example was in Go) which does this and assuming you are doing literal searches is a drop in replacement for re.FindAllIndex https://github.com/boyter/cs/blob/master/str/index.go#L110 https://github.com/boyter/cs/blob/master/str/index.go#L110 which also does simple case folding for you.