[docs] Fwd: possible doc bug: 6.2.1. Regular Expression Syntax, *?, +?, ??

John Gordon john23gordon at gmail.com
Tue Apr 12 01:19:48 EDT 2016


Never mind. I figured it out.

I see that the last sentence about using  .*?  is meant to be used inside
the RE <.*> mentioned in the second sentence. Confusing but another website
explained it then I reread your paragraph and understood what you meant.

- John Gordon


---------- Forwarded message ----------
From: John Gordon <john23gordon at gmail.com>
Date: Mon, Apr 11, 2016 at 12:34 PM
Subject: possible doc bug: 6.2.1. Regular Expression Syntax, *?, +?, ??
To: docs at python.org


I'm a Python newbie and am very reluctant to submit a doc bug since I don't
know what I'm doing yet.

But I'm trying to learn to use re.search and am using your doc.

I can't figure out how the text I colored red below can be accurate.
Besides its logic not making sense to me, I tried running it and it doesn't
work:  .*? doesn't match <H1> .

If I'm wrong I need to understand why.

============

DOC BUG (maybe):
https://docs.python.org/3/library/re.html

6.2.1. Regular Expression Syntax
>
>
> **?, +?, ?? *The '*', '+', and '?' qualifiers are all greedy; they match
> as much text as possible. Sometimes this behaviour isn’t desired; if the RE
> <.*> is matched against '<H1>title</H1>', it will match the entire string,
> and not just '<H1>'. Adding '?' after the qualifier makes it perform the
> match in non-greedy or minimal fashion; as few characters as possible will
> be matched. *Using .*? in the previous expression will match only '<H1>'.*
>
>
I tried the following and none returned <H1>:

>>> ttt = re.search('.*?','<H1>title</H1>')

>>> ttt = re.search('(.*?)','<H1>title</H1>')

>>> ttt = re.search(r'(.*?)','<H1>title</H1>')



Thank you for your time!
John Gordon
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/docs/attachments/20160411/bf61f878/attachment.html>


More information about the docs mailing list