English subtitles

← Hyphenation Solution - Programming Languages

Get Embed Code
5 Languages

Showing Revision 3 created 05/25/2016 by Udacity Robot.

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