使用简单正则表达式的常规表达式(错误) [英] regular expresion (error) in using simple regex

查看:135
本文介绍了使用简单正则表达式的常规表达式(错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在验证,但是正则表达式中有一些错误
我正在做一个用户名字段来验证我正在使用正则表达式,这将允许使用下划线和破折号以及字母和数字.但是下划线和破折号不应放在最后.
所以我用过这个正则表达式
[a-z | A-Z | 0-9] {0,5} [^ _-] $
但是问题是它到底是在中间还是在中间被接受.我不想在这里接受所有符号.
谁能帮我一个忙

i am doing validation but there is some error in regex
i am making a username field to validate i am using regex which will allow underscore and dash and alphabets and numbers. but underscore and dash should not be in the end.
so i have used this regex
[a-z|A-Z|0-9]{0,5}[^_-]$
but the problem is it is dot in the end and in between are accepted. all the symbols are accepted here which i dont want to.
can any one help me out

推荐答案


但是问题是它到底是在中间还是在中间被接受.我不想在这里接受所有符号.
有谁能帮助我

but the problem is it is dot in the end and in between are accepted. all the symbols are accepted here which i dont want to.
can any one help me out


问题是[^_-]正是这样:任何不是"_"或-""的字符-所以实际上,任何字符都可以.如果您要根据文字描述进行操作,请尝试以下操作:
The problem is that [^_-] is exactly this: "Any character which is not a ''_'' or a ''-''" - so literally any character will work. If what you want is as per your text description, try this:
[a-zA-Z0-9_\-]{0,5}[a-zA-Z0-9]



如果要使用正则表达式,请获取 Expresso [


If you are going to work with regular expressions, get a copy of Expresso [^] - it''s free, and it examines and generates Regular expressions.


hey bro. I have made further improvement but its not working. I want expression that will validate if there is dash and underscore in the start. Means username should not include dash or undersocre in starting so i made
^[a-zA-Z0-9_\-]{0,5}[a-zA-Z0-9]


这篇关于使用简单正则表达式的常规表达式(错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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