如何排除 space 作为我的正则表达式的输入

How to exclude space as input on my regex

^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,15}$

我上面的正则表达式工作正常,除了它接受 space 作为输入。如何在我的正则表达式中排除 spaces?

任何与 Perl 相关的正则表达式实现都可以。谢谢

改变

.{8,15}

[^ ]{8,15}                       # No spaces.

\S{8,15}                         # No whitespace.

[A-Za-z0-9#?!@$%^&*\-]{8,15}     # Only allow specific characters.