正则表达式-具有空格和特殊字符 [英] Regex - With Space and Special Characters

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

问题描述

我正在使用以下正则表达式^[a-zA-Z0-9]\s{2,20}$作为输入

I'm using the following Regex ^[a-zA-Z0-9]\s{2,20}$ for input

  • 字母A-Z
  • 字母a-z
  • 数字0-9

输入长度必须至少2个字符,最大20个字符.

The input length must be a least 2 characters and maximum 20 characters.

我也想在输入中启用空格,但只能启用空格,而不是换行等.

I also want to enable space in the input, but only space, not new line, etc.

我最后遇到的问题是我想启用诸如!@#$%^&*)(

Last thing I have problem with is that I want to enable characters such as !@#$%^&*)(

推荐答案

将字符添加到您的正则表达式代码中,就像这样〜

add characters to your regex code like this~

^[a-zA-Z0-9 !@#$%^&*)(]{2,20}$

\s不仅表示空格.

这篇关于正则表达式-具有空格和特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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