...

/

Puzzle 26: Explanation

Puzzle 26: Explanation

Let’s learn how regular expression works in Python.

We'll cover the following...

Try it yourself

Try running the code below to verify the result:

Press + to interact
import re
text = 'The vote was 65 in favour, 43 against and 21 abstentions'
match = re.search(r'(\d+).*(\d+).*(\d+)', text)
print(match.group(1), match.group(2), match.group(3))

Explanation

Most people expect the answer to be 65 43 21. The reason for the actual output is that the .* ...