Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex - match everything without whitespace

I now using in Regex this expressions,

([\x20-\x7E]+) - match everything with space

([\x21-\x7E]+) - match everything without space

But i need more performance and in benchmark i see that (.*) is 2x more faster than ([\x20-\x7E]+). Then i replaced that.

But how to write ([\x21-\x7E]+) in (.*) ? Or in other words how to modify (.*) to match everything without whitespace characters?

Thanks!

like image 771
Svisstack Avatar asked Jan 24 '12 17:01

Svisstack


1 Answers

To match everything except whitespace use:

[^\s]+

or

\S+
like image 104
anubhava Avatar answered Sep 26 '22 13:09

anubhava