Reputation: 35
I wanna catch words that begin with an uppercase followed with either [a-b] or - but it don't seem to work. Here my regular expression I tried ^[A-Z][-[a-z]] How can I fix that?
Upvotes: 0
Views: 42
Reputation: 763
You have an extra set of brackets in there:
var str = "A-abcd";
var str2 = "AA-abcd";
var patt = new RegExp("^[A-Z][-a-z]");
var res = patt.test(str);
console.log(res); // True
var res = patt.test(str2);
console.log(res); // False
Upvotes: 0
Reputation: 17378
You're close. You just have one too many sets of square brackets.
/^[A-Z][a-z\-]/
Upvotes: 1