普通的前pression字母数字空间 [英] Regular expression alphanumerics with space

查看:106
本文介绍了普通的前pression字母数字空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的字母数字常规EX pression,但它没有采取空间。结果
我想空间(字符之间的空白)。结果
我写的是这样的:

  ^ [A-ZA-Z0-9 _] * $


解决方案

有是 \\ S 意思空白转义序列。

更改您的正则表达式这个(添加空格字符的列表):

  ^ [A-ZA-Z0-9 _ \\ S] * $

正如亚历克斯指出, \\ W 表示单词字符,所以你可以进一步缩短:

  ^ [\\ W \\ S] * $

请参阅的方便小抄。

I write regular expression for alphanumerics, but it is not taking space.
I want space (whitespace between characters).
I write like this:

^[a-zA-Z0-9_]*$

解决方案

There is the \s escape sequence that mean "whitespace".

Change you regex to this (adding whitespace to the list of characters):

^[a-zA-Z0-9_\s]*$

As noted by Alex, \w stands for word characters, so you could shorten it further:

^[\w\s]*$

See this handy cheat sheet.

这篇关于普通的前pression字母数字空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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