>我怎么能不允许 – (连续超过1次)?例如AB – Ç
> – 在不允许的单词后面,例如ABC-
> – 在不允许的单词开头,例如-abc
> – 在不允许的单词后面,例如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