English subtitles

← Numbers Solution - Programming Languages

Get Embed Code
3 Languages

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

  1. Let me walk you through one way to do this.
  2. As always, the most important part of a token definition
  3. is the regular expression that it corresponds to.
  4. Here we can optionally start with a minus sign.
  5. Then we definitely have one or more digits, 867, 3, 1.
  6. And then there's a big optional part.
  7. We can have a dot and then some number of digits after that.
  8. We could have the dot and then some number of digits.
  9. -1. is okay or 3.14159.
  10. Here we've got 5 trailing digits. Here we've got 0 of them.
  11. And this whole dot followed by digits is optional.
  12. But remember that the dot has special meaning in regular expressions,
  13. so I'm going to need to use a \ to escape it to say
  14. we literally mean the period and not any character.
  15. Then we turn that string into a floating point number.
  16. Then we return it.
  17. Just to walk through these again, this part, the optional minus sign,
  18. catches either this minus sign or the nothing that's in front of this 3.
  19. And this part here is this 1, this 3, or 867.
  20. This dot, literally a dot, is this dot, that dot,
  21. and I think there was one under here, and then this part
  22. is 14159, 5309,
  23. or the nothing that's here after this dot.