Return to Video

Hyphenation Solution - Programming Languages

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

more » « less
Video Language:
English
Team:
Udacity
Project:
CS262 - Programming Languages
Duration:
01:25

English subtitles

Revisions Compare revisions