正则表达式 - 匹配没有空格的所有内容 [英] Regex - match everything without whitespace

查看:67
本文介绍了正则表达式 - 匹配没有空格的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在在 Regex 中使用这个表达式,

I now using in Regex this expressions,

([\x20-\x7E]+) - 用空格匹配所有内容

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

([\x21-\x7E]+) - 无空格匹配所有内容

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

但我需要更高的性能,在基准测试中我看到 (.*)([\x20-\x7E]+) 快 2x.然后我替换了那个.

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

但是如何在 (.*) 中写 ([\x21-\x7E]+) ?或者换句话说,如何修改 (.*) 以匹配没有空格字符的所有内容?

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

谢谢!

推荐答案

要匹配除空格以外的所有内容,请使用:

To match everything but whitespace use:

[^\s]+

这篇关于正则表达式 - 匹配没有空格的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆