Representing identifiers using Regular Expression

女生的网名这么多〃 提交于 2019-12-03 22:43:51
Oscar Mederos

The regular expression you are looking for is:

[_a-zA-Z][_a-zA-Z0-9]{0,30}

It will match an underscore or letter following by X underscores, letters or numbers, where 0 <= X <= 30

To limit the length, {} are usually used.
For example, your regex was [a-zA-Z0-9]+. Means, allow any alphanumeric values, and the length must be greater than equals to 1. If we want to limit it not to exceed 31 characters, we can rewrite the regex as:

[a-zA-Z0-9]{1,31}

{1,31} indicates that this will accept alphanumeric values of length greater than equals to 1 and less than equals to 31.
You can make respective changes to your regex.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!