Replace regex with string scanning implementation

Removing regular expression usage reduces the microbenchmark running
time by more than half.