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
ae91d090
Kaydet (Commit)
ae91d090
authored
Mar 02, 2009
tarafından
Gregory P. Smith
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Adds an optional flags argument to re.split, re.sub and re.subn to be
consistent with the other re module functions.
üst
0261e5d0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
9 deletions
+24
-9
re.rst
Doc/library/re.rst
+16
-3
re.py
Lib/re.py
+6
-6
NEWS
Misc/NEWS
+2
-0
No files found.
Doc/library/re.rst
Dosyayı görüntüle @
ae91d090
...
@@ -540,7 +540,7 @@ form.
...
@@ -540,7 +540,7 @@ form.
instead.
instead.
.. function:: split(pattern, string[, maxsplit=0])
.. function:: split(pattern, string[, maxsplit=0
, flags=0
])
Split *string* by the occurrences of *pattern*. If capturing parentheses are
Split *string* by the occurrences of *pattern*. If capturing parentheses are
used in *pattern*, then the text of all groups in the pattern are also returned
used in *pattern*, then the text of all groups in the pattern are also returned
...
@@ -555,6 +555,8 @@ form.
...
@@ -555,6 +555,8 @@ form.
['Words', ', ', 'words', ', ', 'words', '.', '']
['Words', ', ', 'words', ', ', 'words', '.', '']
>>> re.split('\W+', 'Words, words, words.', 1)
>>> re.split('\W+', 'Words, words, words.', 1)
['Words', 'words, words.']
['Words', 'words, words.']
>>> re.split('[a-f]+', '0a3B9', flags=re.IGNORECASE)
['0', '3', '9']
If there are capturing groups in the separator and it matches at the start of
If there are capturing groups in the separator and it matches at the start of
the string, the result will start with an empty string. The same holds for
the string, the result will start with an empty string. The same holds for
...
@@ -575,6 +577,9 @@ form.
...
@@ -575,6 +577,9 @@ form.
>>> re.split("(?m)^$", "foo\n\nbar\n")
>>> re.split("(?m)^$", "foo\n\nbar\n")
['foo\n\nbar\n']
['foo\n\nbar\n']
.. versionchanged:: 2.7,3.1
Added the optional flags argument.
.. function:: findall(pattern, string[, flags])
.. function:: findall(pattern, string[, flags])
...
@@ -605,7 +610,7 @@ form.
...
@@ -605,7 +610,7 @@ form.
Added the optional flags argument.
Added the optional flags argument.
.. function:: sub(pattern, repl, string[, count])
.. function:: sub(pattern, repl, string[, count
, flags
])
Return the string obtained by replacing the leftmost non-overlapping occurrences
Return the string obtained by replacing the leftmost non-overlapping occurrences
of *pattern* in *string* by the replacement *repl*. If the pattern isn't found,
of *pattern* in *string* by the replacement *repl*. If the pattern isn't found,
...
@@ -630,6 +635,8 @@ form.
...
@@ -630,6 +635,8 @@ form.
... else: return '-'
... else: return '-'
>>> re.sub('-{1,2}', dashrepl, 'pro----gram-files')
>>> re.sub('-{1,2}', dashrepl, 'pro----gram-files')
'pro--gram files'
'pro--gram files'
>>> re.sub(r'\sAND\s', ' & ', 'Baked Beans And Spam', flags=re.IGNORECASE)
'Baked Beans & Spam'
The pattern may be a string or an RE object; if you need to specify regular
The pattern may be a string or an RE object; if you need to specify regular
expression flags, you must use a RE object, or use embedded modifiers in a
expression flags, you must use a RE object, or use embedded modifiers in a
...
@@ -650,12 +657,18 @@ form.
...
@@ -650,12 +657,18 @@ form.
character ``'0'``. The backreference ``\g<0>`` substitutes in the entire
character ``'0'``. The backreference ``\g<0>`` substitutes in the entire
substring matched by the RE.
substring matched by the RE.
.. versionchanged:: 2.7,3.1
Added the optional flags argument.
.. function:: subn(pattern, repl, string[, count])
.. function:: subn(pattern, repl, string[, count
, flags
])
Perform the same operation as :func:`sub`, but return a tuple ``(new_string,
Perform the same operation as :func:`sub`, but return a tuple ``(new_string,
number_of_subs_made)``.
number_of_subs_made)``.
.. versionchanged:: 2.7,3.1
Added the optional flags argument.
.. function:: escape(string)
.. function:: escape(string)
...
...
Lib/re.py
Dosyayı görüntüle @
ae91d090
...
@@ -141,16 +141,16 @@ def search(pattern, string, flags=0):
...
@@ -141,16 +141,16 @@ def search(pattern, string, flags=0):
a match object, or None if no match was found."""
a match object, or None if no match was found."""
return
_compile
(
pattern
,
flags
)
.
search
(
string
)
return
_compile
(
pattern
,
flags
)
.
search
(
string
)
def
sub
(
pattern
,
repl
,
string
,
count
=
0
):
def
sub
(
pattern
,
repl
,
string
,
count
=
0
,
flags
=
0
):
"""Return the string obtained by replacing the leftmost
"""Return the string obtained by replacing the leftmost
non-overlapping occurrences of the pattern in string by the
non-overlapping occurrences of the pattern in string by the
replacement repl. repl can be either a string or a callable;
replacement repl. repl can be either a string or a callable;
if a string, backslash escapes in it are processed. If it is
if a string, backslash escapes in it are processed. If it is
a callable, it's passed the match object and must return
a callable, it's passed the match object and must return
a replacement string to be used."""
a replacement string to be used."""
return
_compile
(
pattern
,
0
)
.
sub
(
repl
,
string
,
count
)
return
_compile
(
pattern
,
flags
)
.
sub
(
repl
,
string
,
count
)
def
subn
(
pattern
,
repl
,
string
,
count
=
0
):
def
subn
(
pattern
,
repl
,
string
,
count
=
0
,
flags
=
0
):
"""Return a 2-tuple containing (new_string, number).
"""Return a 2-tuple containing (new_string, number).
new_string is the string obtained by replacing the leftmost
new_string is the string obtained by replacing the leftmost
non-overlapping occurrences of the pattern in the source
non-overlapping occurrences of the pattern in the source
...
@@ -159,12 +159,12 @@ def subn(pattern, repl, string, count=0):
...
@@ -159,12 +159,12 @@ def subn(pattern, repl, string, count=0):
callable; if a string, backslash escapes in it are processed.
callable; if a string, backslash escapes in it are processed.
If it is a callable, it's passed the match object and must
If it is a callable, it's passed the match object and must
return a replacement string to be used."""
return a replacement string to be used."""
return
_compile
(
pattern
,
0
)
.
subn
(
repl
,
string
,
count
)
return
_compile
(
pattern
,
flags
)
.
subn
(
repl
,
string
,
count
)
def
split
(
pattern
,
string
,
maxsplit
=
0
):
def
split
(
pattern
,
string
,
maxsplit
=
0
,
flags
=
0
):
"""Split the source string by the occurrences of the pattern,
"""Split the source string by the occurrences of the pattern,
returning a list containing the resulting substrings."""
returning a list containing the resulting substrings."""
return
_compile
(
pattern
,
0
)
.
split
(
string
,
maxsplit
)
return
_compile
(
pattern
,
flags
)
.
split
(
string
,
maxsplit
)
def
findall
(
pattern
,
string
,
flags
=
0
):
def
findall
(
pattern
,
string
,
flags
=
0
):
"""Return a list of all non-overlapping matches in the string.
"""Return a list of all non-overlapping matches in the string.
...
...
Misc/NEWS
Dosyayı görüntüle @
ae91d090
...
@@ -163,6 +163,8 @@ Core and Builtins
...
@@ -163,6 +163,8 @@ Core and Builtins
- Issue #3582: Use native TLS functions on Windows
- Issue #3582: Use native TLS functions on Windows
- The re.sub(), re.subn() and re.split() functions now accept a flags parameter.
Library
Library
-------
-------
...
...
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