Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)

In Python, I came to know that the (?P<group_name>…) syntax allows us to refer to the matched string through its name:

>>> import re

>>> match = re.search('(?P<name>.*) (?P<phone>.*)', 'John 123456')

>>> match.group('name')

'John'

What does that "P" mean in the syntax? 

1 Answer

0 votes
by (107k points)

That P in the syntax is for the Pattern! The association names a (sub)pattern for succeeding use in the regex. Everything is a pattern, though, in a regexp.

If you want to learn more about python training then do check out the below python tutorial video for better understanding:

Related questions

0 votes
4 answers
0 votes
1 answer
asked Nov 22, 2020 in Python by ashely (50.2k points)
0 votes
1 answer
0 votes
1 answer
asked Dec 6, 2020 in Python by ashely (50.2k points)

1.2k questions

2.7k answers

501 comments

693 users

Browse Categories

...