正则表达式连续不允许超过1个破折号

前端之家收集整理的这篇文章主要介绍了正则表达式连续不允许超过1个破折号前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
>我怎么能不允许 – (连续超过1次)?例如AB – Ç
> – 在不允许的单词后面,例如ABC-
> – 在不允许的单词开头,例如-abc

^ [A-Za-z0-9-] $是我到目前为止所拥有的.

^(?!-)(?!.*--)[A-Za-z0-9-]+(?<!-)$

说明:

^             # Anchor at start of string
(?!-)         # Assert that the first character isn't a -
(?!.*--)      # Assert that there are no -- present anywhere
[A-Za-z0-9-]+ # Match one or more allowed characters
(?<!-)        # Assert that the last one isn't a -
$            # Anchor at end of string

猜你在找的正则表达式相关文章