我需要一个正则表达式来验证以下条件,
1) include - (dash) and _ (underscore) as valid components.
2) cannot end with (dash) and (underscore).我正在使用这个- ^[A-Za-z0-9]+([-_]+[A-Za-z0-9]+)*$,但不确定如何包含第二个条件,即-不能以破折号或下划线结束
发布于 2014-02-05 00:21:03
您可以使用以下代码:
^[^-_].*[^-_]$它不能以-或_ = ^[^-_]开头,也不能以-或_ = [^-_]$结尾
https://stackoverflow.com/questions/21557658
复制相似问题