Capture group of python version

Hi all. I am not sure that i understand how does ( ) use.

This is the solution from DQ. pattern = r"[Pp]ython ([\d\.]+)" if we want to capture a group of python version, shouldn’t we put ( )outside the whole re? like pattern = r"([Pp]ython [\d\.]+)".

And what does \ mean infort of .?

Thank you!!

Hi!
You put the parenthesis only for the substring you want to capture, not for the whole expression. In this mission we are asked to extract only the versions of Python in format "2.0, 3, etc.) and not “Python 2.0, Python 3”.
On the hand the \ before the . helps us to escape the . as a special character (which means any symbol if I’m not mistaken).

1 Like

This will help you understand your regex. Always try these sites when you get confused about your regex.

See the results for, r"[Pp]ython ([\d\.]+)"

and for r"([Pp]ython [\d\.]+)"