If you do not want to match mutiple dashes after eachother:
^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$
This will match: a
, a-a
, aaa-a
, aaa-a-aaa-a-aaa-a
, etc
But not: -
, -a
, a-
, a--a
, a-a-a-
, a-a--a
, etc.
More Related Contents:
- How can I validate an email address using a regular expression?
- My regex is matching too much. How do I make it stop? [duplicate]
- Reference – Password Validation
- Regular Expressions: Is there an AND operator?
- How to negate the whole regex?
- How to validate phone numbers using regex
- Regex whitespace word boundary
- Regular Expressions and negating a whole character group [duplicate]
- Decimal number regular expression, where digit after decimal is optional
- Extract info inside all parenthesis in R
- Regex for route matching in Express
- How can I match a pattern as long as it’s not at the beginning with regex?
- AWK: Access captured group from line pattern
- How to extract string following a pattern with grep, regex or perl [duplicate]
- Search and replace in bash using regular expressions
- Regular expression for parsing name value pairs
- Need a regular expression – disallow all zeros
- How to match a line not containing a word [duplicate]
- Regular expression to extract whole sentences with matching word
- Case insensitive search in Mongo
- Find all string matches with Regex golang
- Replace with whole match value using Notepad++ regex search and replace
- Regular Expression usage with ls
- Remove everything except a certain pattern
- Match parenthesised block using regular expressions in vim
- How to extract multiple values with a regular expression in Jmeter
- RegularExpressionAttribute – How to make it not case sensitive for client side validation?
- How do you match a caret (^) symbol in regex?
- Private IP Address Identifier in Regular Expression
- How to prevent regmatches drop non matches?