Don't replace spaces with \s. \s would be slower since it matches spaces, tabs, carriage returns (I think) and line feeds, and even more if it's a unicode string. "\x20", "\040", "\", and "[ ]" work. (I wonder if the last is slower than the others. I'll Benchmark later.)
You've also added useless captures. Don't use (...) (which incures a speed penalty), use (?:...).
In reply to Re^2: Search and Replace.
by ikegami
in thread Search and Replace.
by Doniv
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |