正则表达式为一个或多个字母/数字和零或更多空格 [英] Regex for ONE-or-more letters/digits And ZERO-or-more spaces

查看:575
本文介绍了正则表达式为一个或多个字母/数字和零或更多空格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在字符串中允许0个或更多空格,在字符串中允许一个或多个AZ或az或0-9。

I want to allow 0 or more white spaces in my string and one or more A-Z or a-z or 0-9 in my string.

Regex允许Java中的空格字符

建议 [0-9A-Za-z] +

我对此表示怀疑,此正则表达式匹配具有零个或多个空格的模式。

I doubt that, this regex matches patterns having zero or more white spaces.

如何在字符串中的任何位置允许0个或更多个空格以及在字符串中的任何位置使用一个或多个字符。

What to do to allow 0 or more whitespaces anywhere in the string and one or more characters anywhere in the string.

这会有效吗? ([0-9A-Za-z] +)([] *)

推荐答案

我相信你可以这样做:

([ ]*+[0-9A-Za-z]++[ ]*+)+

这是0或更多空格,其后至少是1个alphanum char,后跟0个或更多个空格

This is 0 or more spaces, followed by at least 1 alphanum char, followed by 0 or more spaces

^^整个事情至少一次。

^^ that whole thing at least once.

使用Pshemo关于占有量词的想法可以加速正则表达式。

Using Pshemo's idea of possessive quantifiers to speed up the regex.

这篇关于正则表达式为一个或多个字母/数字和零或更多空格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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