* Remove spaces - myString.replace(/\u0020+/g, "");
* Remove common line terminators - myString.replace(/(\r|\n)+/g, "");
* Remove all white space - myString.replace(/\s+/g, "");
* Remove spaces - myString.replace(/\u0020+/g, "");
* Remove common line terminators - myString.replace(/(\r|\n)+/g, "");
* Remove all white space - myString.replace(/\s+/g, "");
So it's not quite the fastest possible because it doesn't use SIMD, but this is mostly because we don't have good explicit SIMD support on stable Rust yet. Once we do, this immediately becomes a strong candidate to optimize to something like the OP's fastest version (and also probably generalizing to AVX2 instructions as well).
N.B. My sibling comment linked to my blog post on ripgrep, which uses Rust's regex engine. ;-)
[1] - https://github.com/BurntSushi/rust-memchr/blob/master/src/li...
https://swtch.com/~rsc/regexp/
I've had nothing but good experiences with it. (Rust's looks similar, by the way, and quite impressive.)
Regular Expressions are efficient in that one line of code can save you writing hundreds of lines. But they're normally slower (even pre-compiled) than thoughtful hand written code simply due to the overhead.
Generally the simpler the objective the worse Regular Expressions are. They're better for complex operations. Plus people write regular expressions REALLY poorly, doubly so for UNICODE.
Ideally you should use the standard library for this. For example C# has Char.IsWhiteSpace() which supports tons of UNICODE whitespace and can be updated with whitespace which doesn't even exist today.
You're responding to a point never made.
those engines too trade power for speed.