Find the list

Report a typo

Let's try to write a template that matches a numbered list. Here are examples of a numbered list in this task:

1) Curiosity 2) Perseverance 3) ?

1) cabbage 2) carrot 3) apple 4) oranges

Note that:

  • your template must match the whole list, not just one item

  • there can be any number of items in the list. The number of items in the list may vary.

  • your template shouldn't match the text preceding the list

  • one whitespace separates one number (for example, 2)) from the text on both sides.

  • however, there's no whitespace before the number of the first item (i.e., no whitespace before 1))

  • also, there's no space after the last item on the list.

Put your regex in the template variable.

If you don't come up with a valid regex immediately, don't get sad! It may be not as easy as it looks. Open the website allowing you to check your expression online, copy the example of a numbered list and try to match it with your expression.

Don't forget to escape special symbols such as ) when they should be interpreted literally. Make use of the plus + quantifier. If your expression doesn't match the last item of the list, try to add to the end of the regex a separate part matching the last item specifically.

Write a program in Python 3
import re


# put your regex in the variable template
template = ""
___

Create a free account to access the full topic