我需要一个正则表达式来验证以下条件,
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:22:08
使用以下内容:
^.*[^-_]$这允许从开头(^.*)到结尾($)的任何字符序列中使用除短划线或下划线([^-_])以外的任何字符。如果有效的非结束字符仅为字母加-_,则使用[A-Za-z0-9-_]*而不是.*。
发布于 2014-02-05 00:21:03
您可以使用以下代码:
^[^-_].*[^-_]$它不能以-或_ = ^[^-_]开头,也不能以-或_ = [^-_]$结尾
https://stackoverflow.com/questions/21557658
复制相似问题