4 ms·
I wonder whether it would help to match from both sides (start and end) simultaneously, since you know you're not looking in the middle of the string. You also
by maweki 10y ago
I wonder whether it would help to match from both sides (start and end) simultaneously, since you know you're not looking in the middle of the string. You also don't care about capture groups.
- rsc 10y agoIt would help this example. It wouldn't help the general case.
- maweki 10y agoBut in general the reversal of a glob pattern is trivial while the reversal of the equivalent regular expression is not, no?
- rsc 10y agoReversing a regular expression and reversing a glob are about the same: you just flip everything around and you're done. In fact RE2 uses this fact to speed up regexp searches. See https://swtch.com/~rsc/regexp/regexp3.html#submatch https://swtch.com/~rsc/regexp/regexp3.html#submatch and scan ahead a bit for "Run the DFA backward".