Advanced Regular Expression

pattern = r"[Pp]ython ([\d.]+)"

Screen Link:

My Code:

pattern =r"[Pp]ython ?([\d.]+)"

What I expected to happen:

I expect this to be correct

What actually happened:

Value of py_versions_freq is not what we expected.
'

In the “Learn” section, it said that ‘All of these examples have a number after the word “Python,” which indicates a version number. Sometimes a space precedes the number, sometimes it doesn’t.’

Thus, I would expect that we need a question mark after the space to match the cases where there is no space preceding the number?

Thank you!

1 Like