Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
7438e4b5
Kaydet (Commit)
7438e4b5
authored
Eki 10, 2014
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue 1519638: Now unmatched groups are replaced with empty strings in re.sub()
and re.subn().
üst
365e2823
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
26 additions
and
8 deletions
+26
-8
re.rst
Doc/library/re.rst
+8
-0
3.5.rst
Doc/whatsnew/3.5.rst
+3
-0
sre_parse.py
Lib/sre_parse.py
+3
-5
test_re.py
Lib/test/test_re.py
+8
-2
NEWS
Misc/NEWS
+4
-1
No files found.
Doc/library/re.rst
Dosyayı görüntüle @
7438e4b5
...
...
@@ -701,6 +701,9 @@ form.
.. versionchanged:: 3.1
Added the optional flags argument.
.. versionchanged:: 3.5
Unmatched groups are replaced with an empty string.
.. function:: subn(pattern, repl, string, count=0, flags=0)
...
...
@@ -710,6 +713,9 @@ form.
.. versionchanged:: 3.1
Added the optional flags argument.
.. versionchanged:: 3.5
Unmatched groups are replaced with an empty string.
.. function:: escape(string)
...
...
@@ -885,6 +891,8 @@ Match objects support the following methods and attributes:
(``\g<1>``, ``\g<name>``) are replaced by the contents of the
corresponding group.
.. versionchanged:: 3.5
Unmatched groups are replaced with an empty string.
.. method:: match.group([group1, ...])
...
...
Doc/whatsnew/3.5.rst
Dosyayı görüntüle @
7438e4b5
...
...
@@ -223,6 +223,9 @@ re
* Number of capturing groups in regular expression is no longer limited by 100.
(Contributed by Serhiy Storchaka in :issue:`22437`.)
* Now unmatched groups are replaced with empty strings in :func:`re.sub`
and :func:`re.subn`. (Contributed by Serhiy Storchaka in :issue:`1519638`.)
shutil
------
...
...
Lib/sre_parse.py
Dosyayı görüntüle @
7438e4b5
...
...
@@ -880,14 +880,12 @@ def parse_template(source, pattern):
def
expand_template
(
template
,
match
):
g
=
match
.
group
sep
=
match
.
string
[:
0
]
empty
=
match
.
string
[:
0
]
groups
,
literals
=
template
literals
=
literals
[:]
try
:
for
index
,
group
in
groups
:
literals
[
index
]
=
s
=
g
(
group
)
if
s
is
None
:
raise
error
(
"unmatched group"
)
literals
[
index
]
=
g
(
group
)
or
empty
except
IndexError
:
raise
error
(
"invalid group reference"
)
return
sep
.
join
(
literals
)
return
empty
.
join
(
literals
)
Lib/test/test_re.py
Dosyayı görüntüle @
7438e4b5
...
...
@@ -225,9 +225,11 @@ class ReTests(unittest.TestCase):
self
.
assertRaises
(
re
.
error
,
re
.
sub
,
'(?P<a>x)'
,
'
\
g<a a>'
,
'xx'
)
self
.
assertRaises
(
re
.
error
,
re
.
sub
,
'(?P<a>x)'
,
'
\
g<>'
,
'xx'
)
self
.
assertRaises
(
re
.
error
,
re
.
sub
,
'(?P<a>x)'
,
'
\
g<1a1>'
,
'xx'
)
self
.
assertRaises
(
re
.
error
,
re
.
sub
,
'(?P<a>x)'
,
r'\g<2>'
,
'xx'
)
self
.
assertRaises
(
re
.
error
,
re
.
sub
,
'(?P<a>x)'
,
r'\2'
,
'xx'
)
self
.
assertRaises
(
IndexError
,
re
.
sub
,
'(?P<a>x)'
,
'
\
g<ab>'
,
'xx'
)
self
.
assert
Raises
(
re
.
error
,
re
.
sub
,
'(?P<a>x)|(?P<b>y)'
,
'
\
g<b>'
,
'xx
'
)
self
.
assert
Raises
(
re
.
error
,
re
.
sub
,
'(?P<a>x)|(?P<b>y)'
,
'
\\
2'
,
'xx
'
)
self
.
assert
Equal
(
re
.
sub
(
'(?P<a>x)|(?P<b>y)'
,
r'\g<b>'
,
'xx'
),
'
'
)
self
.
assert
Equal
(
re
.
sub
(
'(?P<a>x)|(?P<b>y)'
,
r'\2'
,
'xx'
),
'
'
)
self
.
assertRaises
(
re
.
error
,
re
.
sub
,
'(?P<a>x)'
,
'
\
g<-1>'
,
'xx'
)
# New valid/invalid identifiers in Python 3
self
.
assertEqual
(
re
.
sub
(
'(?P<µ>x)'
,
r'\g<µ>'
,
'xx'
),
'xx'
)
...
...
@@ -439,6 +441,10 @@ class ReTests(unittest.TestCase):
"first second"
)
.
expand
(
r"\2 \1 \g<second> \g<first>"
),
"second first second first"
)
self
.
assertEqual
(
re
.
match
(
"(?P<first>first)|(?P<second>second)"
,
"first"
)
.
expand
(
r"\2 \g<second>"
),
" "
)
def
test_repeat_minmax
(
self
):
self
.
assertIsNone
(
re
.
match
(
"^(
\
w){1}$"
,
"abc"
))
...
...
Misc/NEWS
Dosyayı görüntüle @
7438e4b5
...
...
@@ -166,7 +166,10 @@ Core and Builtins
Library
-------
-
Issue
$
18615
:
sndhdr
.
what
/
whathdr
now
return
a
namedtuple
.
-
Issue
1519638
:
Now
unmatched
groups
are
replaced
with
empty
strings
in
re
.
sub
()
and
re
.
subn
().
-
Issue
#
18615
:
sndhdr
.
what
/
whathdr
now
return
a
namedtuple
.
-
Issue
#
22462
:
Fix
pyexpat
's creation of a dummy frame to make it
appear in exception tracebacks.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment