Interesting, I didn't know strings.Map could work this way, I have done a performance benchmark with PHP 7 Pcre2 C is 1,020 nanoseconds and strings.Map version is 2,888 nanoseconds, not bad improvement over regexp. If there is a better approach, however, Rust Re2 is just as fast as PHP Pcre2.