Custom indexOf for strings javascript with regex
Too sad, it's not O(1).
There is a cost for: 


Constructing the regex into a DFA
Calling test() or match() on the regex for the value


Complexities:


A well implemented regex construction will be O(M) where M is the length of the key.
While test/matching it afterwards will be O(N) where N is the length of the value. (best case, e.g. regexes with backtracking can result in horrible complexities) 


So a couple of improvements can be:


if the key is always the same. Construct the regex for the key only once.
first start with comparing the length of the value and key before calling the more expensive test()-match() methods.
apart from that, the idea of a regex is ok but I don't know if it's the most understandable way of writing an indexOf.
Reference: Regex Complexities on SO