You can do this
/^[^-]+-[^-]+$/
^
depicts the start of the string
$
depicts the end of the string
[^-]+
matches 1 to many characters except -
More Related Contents:
- Regex – To allow numeric, only characters R, N, X, B, @ [closed]
- Find particular string from URL in JavaScript
- Regex for Email Address along with name format [duplicate]
- JavaScript regex multiline text between two tags
- Case insensitive regex in JavaScript
- I want to remove double quotes from a String
- Count number of matches of a regex in Javascript
- Password REGEX with min 6 chars, at least one letter and one number and may contain special characters
- Regex created via new RegExp(myString) not working (backslashes)
- Replace a Regex capture group with uppercase in Javascript
- Replacing from javascript dom text node
- Javascript Regex to replace text NOT in html attributes [duplicate]
- Replacing the nth instance of a regex match in Javascript
- How to extract a string using JavaScript Regex?
- What does the regular expression /_/g mean?
- Interesting test of Javascript RegExp [duplicate]
- Regex only capturing last instance of capture group in match
- What are non-word boundary in regex (\B), compared to word-boundary?
- Javascript RegExp for splitting text into sentences and keeping the delimiter
- Best way to parse HTML in Javascript
- Commenting Regular Expressions
- JavaScript Regex to match a URL in a field of text
- Regular Expression Pattern With A Variable
- javascript regex : only english letters allowed
- Javascript function need allow numbers, dot and comma
- Remove everything within script and style tags
- URL regex validation
- In JavaScript, how can I replace text in an HTML page without affecting the tags?
- JavaScript: RegExp constructor vs RegEx literal
- Find and replace nth occurrence of [bracketed] expression in string