Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7771781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:44:03+00:00 2026-06-01T16:44:03+00:00

In Python, the (?P<group_name>…) syntax allows one to refer to the matched string through

  • 0

In Python, the (?P<group_name>…) syntax allows one 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 “P” stand for? I could not find any hint in the official documentation.

I would love to get ideas about how to help my students remember this syntax. Knowing what “P” does stand for (or might stand for) would be useful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T16:44:04+00:00Added an answer on June 1, 2026 at 4:44 pm

    Since we’re all guessing, I might as well give mine: I’ve always thought it stood for Python. That may sound pretty stupid — what, P for Python?! — but in my defense, I vaguely remembered this thread [emphasis mine]:

    Subject: Claiming (?P…) regex syntax extensions

    From: Guido van Rossum (gui…@CNRI.Reston.Va.US)

    Date: Dec 10, 1997 3:36:19 pm

    I have an unusual request for the Perl developers (those that develop
    the Perl language). I hope this (perl5-porters) is the right list. I
    am cc’ing the Python string-sig because it is the origin of most of
    the work I’m discussing here.

    You are probably aware of Python. I am Python’s creator; I am
    planning to release a next “major” version, Python 1.5, by the end of
    this year. I hope that Python and Perl can co-exist in years to come;
    cross-pollination can be good for both languages. (I believe Larry
    had a good look at Python when he added objects to Perl 5; O’Reilly
    publishes books about both languages.)

    As you may know, Python 1.5 adds a new regular expression module that
    more closely matches Perl’s syntax. We’ve tried to be as close to the
    Perl syntax as possible within Python’s syntax. However, the regex
    syntax has some Python-specific extensions, which all begin with (?P .
    Currently there are two of them:

    (?P<foo>...) Similar to regular grouping parentheses, but the text
    matched by the group is accessible after the match has been performed,
    via the symbolic group name “foo”.

    (?P=foo) Matches the same string as that matched by the group named
    “foo”. Equivalent to \1, \2, etc. except that the group is referred
    to by name, not number.

    I hope that this Python-specific extension won’t conflict with any
    future Perl extensions to the Perl regex syntax. If you have plans to
    use (?P, please let us know as soon as possible so we can resolve the
    conflict. Otherwise, it would be nice if the (?P syntax could be
    permanently reserved for Python-specific syntax extensions.
    (Is
    there some kind of registry of extensions?)

    to which Larry Wall replied:

    […] There’s no registry as of now–yours is the first request from
    outside perl5-porters, so it’s a pretty low-bandwidth activity.
    (Sorry it was even lower last week–I was off in New York at Internet
    World.)

    Anyway, as far as I’m concerned, you may certainly have ‘P’ with my
    blessing. (Obviously Perl doesn’t need the ‘P’ at this point. 🙂 […]

    So I don’t know what the original choice of P was motivated by — pattern? placeholder? penguins? — but you can understand why I’ve always associated it with Python. Which considering that (1) I don’t like regular expressions and avoid them wherever possible, and (2) this thread happened fifteen years ago, is kind of odd.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Python's getattr() method is useful when you don't know the name of a certain
python decimal comparison >>> from decimal import Decimal >>> Decimal('1.0') > 2.0 True I
The Zen of Python states that there should only be one way to do
I'm using Python to parse a file in search for e-mail addresses, but I
I am looking for a code in python that allows me to take a
Django/Python noob here! Here are my models: class Match(models.Model): date = models.DateTimeField() court =
I'm trying to match a label within a valid domain name using a regular
I am programming in python and need to access the name I have given
Here is the code: 1 #!/usr/bin/env python 2 3 import re, os, sys, jira,
If a group of Python developers wants to put their shared code somewhere, in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.