QuestionQ13

Regular Expressions

What output results when the following commands are entered in Python interactive mode?

Question Image

  • A ['tag to go tag', 'to sans tag']
  • B ['tag to go tag', 'tag to sans tag']
  • C ['tag to go tag']
  • D ['tag to go tag to sans tag']
Explanation

In Python regular expressions, .* is greedy by default. Between the first and final literal tag, it consumes the longest possible sequence, so re.findall() returns one string: tag to go tag to sans tag.

Community Discussion

No comments yet. Be the first to start the discussion!