English subtitles

← Find Html Tags Solution - Design of Computer Programs

Get Embed Code
2 Languages

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

  1. Here's my solution to the findtags problem.
  2. I decided to do it just using regular expressions.
  3. Why don't I make that explicit and import the regular expression module,
  4. but then I broke up my regular expression, because they can get long and complicated.
  5. I said there is a part where I'm parsing the parameters,
  6. and that's one or more word characters, an equal sign, and then a quoted string.
  7. A quote character, 0 or more non-quote characters, followed by a quote character.
  8. Then that whole thing we can have zero or more parameters.
  9. The thing that made it complicated is I've got to throw in optional spaces in multiple positions--
  10. " \s* " means zero or more spaces.
  11. That defines a set of parameters.
  12. Then the tag is the angle bracket, maybe some spaces, word character--
  13. like the a or the table tag, then the parameters, then maybe some more spaces,
  14. and then the close. The close is an angle bracket.
  15. I allowed an optional slash-angle bracket there.
  16. Now that I've defined this regular expression in tags,
  17. then I just re.findall of the tags in the text.