-
Here's a pretty good answer.
-
We definitely want to match single words and then you can possibly have 1 hypen
-
and then you can have more letters if you like.
-
This regular expression definitely matches well-liked.
-
It also matches html--maybe the h, t, and m will match the first part,
-
and the l will match the second part.
-
It definitely rejects a-b-c and a--b.
-
However, 1 problem with this regular expression is that it does not accept
-
single letter words like "a" or "i".
-
To see why, just look at these 2 plus signs.
-
This requires 1 or more letters here and 1 or more letters there,
-
That's at least 2 letters.
-
We might be tempted to fix it up by making 1 of these a star,
-
but now we mistakenly accept things like just "-a".
-
No letters here, the hypen, and then some more letters--
-
well, that didn't work.
-
What if I try to make the other one a star?
-
Well, dual problem--now we'll mistakenly accept things like "a-".
-
Well, this is a bit of a challenge.
-
What we really want is for this hypen and the second word to be grouped together,
-
and either they're both there or they're not.
-
It's as if I really want this question mark to apply to both the hyphen
-
and also the [a - z]+.
-
We don't know how to do that yet, but you'll get a chance after we've learned how
-
to fix this up in the homework.