[Python-bugs-list] [ python-Bugs-574594 ] Search/Expand fails on 2nd set of [ & ]
noreply@sourceforge.net
noreply@sourceforge.net
Thu, 27 Jun 2002 07:25:04 -0700
Bugs item #574594, was opened at 2002-06-27 16:04
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=574594&group_id=5470
Category: Regular Expressions
>Group: Not a Bug
>Status: Closed
>Resolution: Wont Fix
Priority: 5
Submitted By: Moshe Yudkowsky (myudkowsky)
Assigned to: Fredrik Lundh (effbot)
Summary: Search/Expand fails on 2nd set of [ & ]
Initial Comment:
Search followed by an expand or group() fails to select
any data from the string being searched when
(a) the search pattern seeks a [ and ] in the string, and
(b) the string contains two pairs of [ and ].
I.e., if the search pattern is
"\[spam.*\] *(.*)"
and then we search two strings:
str1 = "[spam score 10/10] Spammer Junk"
str2 = "[spam score 10/10] Spammer Junk [spammer's token]"
we should match, and then be able to expand, the entire
remainder of the string excluding the opening [spam
score.*]. However, this only works for the first
string; the second string fails.
I regret to say that the resolution of this problem is
not obvious from the source file.
----------------------------------------------------------------------
>Comment By: Fredrik Lundh (effbot)
Date: 2002-06-27 16:25
Message:
Logged In: YES
user_id=38376
it may be surprising, but this is the expected behaviour:
the "*" operator always matches as much as it possibly can.
in your second example, the ".*\]" part matches the entire
second string, and the " *(.*)" then happily matches the rest
(an empty string).
I suggest changing the pattern to:
"\[spam[^\]]*\] *(.*)"
</F>
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=574594&group_id=5470