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
8646e8ea
Kaydet (Commit)
8646e8ea
authored
Eyl 17, 2012
tarafından
Ezio Melotti
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
#15920: merge with 3.2.
üst
07085332
13bec9b3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
13 deletions
+13
-13
regex.rst
Doc/howto/regex.rst
+13
-13
No files found.
Doc/howto/regex.rst
Dosyayı görüntüle @
8646e8ea
...
@@ -260,7 +260,7 @@ performing string substitutions. ::
...
@@ -260,7 +260,7 @@ performing string substitutions. ::
>>> import re
>>> import re
>>> p = re.compile('ab*')
>>> p = re.compile('ab*')
>>> p
>>> p
#doctest: +ELLIPSIS
<
_sre
.
SRE_Pattern
object
at
0x
...
>
<
_sre
.
SRE_Pattern
object
at
0x
...
>
:func:`re.compile` also accepts an optional *flags* argument, used to enable
:func:`re.compile` also accepts an optional *flags* argument, used to enable
...
@@ -372,7 +372,7 @@ Python interpreter, import the :mod:`re` module, and compile a RE::
...
@@ -372,7 +372,7 @@ Python interpreter, import the :mod:`re` module, and compile a RE::
>>> import re
>>> import re
>>> p = re.compile('[a-z]+')
>>> p = re.compile('[a-z]+')
>>> p
>>> p
#doctest: +ELLIPSIS
<
_sre
.
SRE_Pattern
object
at
0x
...
>
<
_sre
.
SRE_Pattern
object
at
0x
...
>
Now, you can try matching various strings against the RE ``[a-z]+``. An empty
Now, you can try matching various strings against the RE ``[a-z]+``. An empty
...
@@ -390,7 +390,7 @@ case, :meth:`match` will return a :class:`MatchObject`, so you should store the
...
@@ -390,7 +390,7 @@ case, :meth:`match` will return a :class:`MatchObject`, so you should store the
result in a variable for later use. ::
result in a variable for later use. ::
>>> m = p.match('tempo')
>>> m = p.match('tempo')
>>> m
>>> m
#doctest: +ELLIPSIS
<
_sre
.
SRE_Match
object
at
0x
...
>
<
_sre
.
SRE_Match
object
at
0x
...
>
Now you can query the :class:`MatchObject` for information about the matching
Now you can query the :class:`MatchObject` for information about the matching
...
@@ -429,7 +429,7 @@ case. ::
...
@@ -429,7 +429,7 @@ case. ::
>>> print(p.match('::: message'))
>>> print(p.match('::: message'))
None
None
>>> m = p.search('::: message')
; print(m)
>>> m = p.search('::: message')
; print(m) #doctest: +ELLIPSIS
<
_sre
.
SRE_Match
object
at
0x
...
>
<
_sre
.
SRE_Match
object
at
0x
...
>
>>> m.group()
>>> m.group()
'message'
'message'
...
@@ -458,7 +458,7 @@ result. The :meth:`finditer` method returns a sequence of :class:`MatchObject`
...
@@ -458,7 +458,7 @@ result. The :meth:`finditer` method returns a sequence of :class:`MatchObject`
instances as an :term:`iterator`::
instances as an :term:`iterator`::
>>> iterator = p.finditer('12 drummers drumming, 11 ... 10 ...')
>>> iterator = p.finditer('12 drummers drumming, 11 ... 10 ...')
>>> iterator
>>> iterator
#doctest: +ELLIPSIS
<callable
_iterator
object
at
0x
...
>
<callable
_iterator
object
at
0x
...
>
>>> for match in iterator:
>>> for match in iterator:
... print(match.span())
... print(match.span())
...
@@ -480,7 +480,7 @@ the RE string added as the first argument, and still return either ``None`` or a
...
@@ -480,7 +480,7 @@ the RE string added as the first argument, and still return either ``None`` or a
>>> print(re.match(r'From\s+', 'Fromage amk'))
>>> print(re.match(r'From\s+', 'Fromage amk'))
None
None
>>> re.match(r'From\s+', 'From amk Thu May 14 19:12:10 1998')
>>> re.match(r'From\s+', 'From amk Thu May 14 19:12:10 1998')
#doctest: +ELLIPSIS
<
_sre
.
SRE_Match
object
at
0x
...
>
<
_sre
.
SRE_Match
object
at
0x
...
>
Under the hood, these functions simply create a pattern object for you
Under the hood, these functions simply create a pattern object for you
...
@@ -682,7 +682,7 @@ given location, they can obviously be matched an infinite number of times.
...
@@ -682,7 +682,7 @@ given location, they can obviously be matched an infinite number of times.
For example, if you wish to match the word ``From`` only at the beginning of a
For example, if you wish to match the word ``From`` only at the beginning of a
line, the RE to use is ``^From``. ::
line, the RE to use is ``^From``. ::
>>> print(re.search('^From', 'From Here to Eternity'))
>>> print(re.search('^From', 'From Here to Eternity'))
#doctest: +ELLIPSIS
<
_sre
.
SRE_Match
object
at
0x
...
>
<
_sre
.
SRE_Match
object
at
0x
...
>
>>> print(re.search('^From', 'Reciting From Memory'))
>>> print(re.search('^From', 'Reciting From Memory'))
None
None
...
@@ -694,11 +694,11 @@ given location, they can obviously be matched an infinite number of times.
...
@@ -694,11 +694,11 @@ given location, they can obviously be matched an infinite number of times.
Matches at the end of a line, which is defined as either the end of the string,
Matches at the end of a line, which is defined as either the end of the string,
or any location followed by a newline character. ::
or any location followed by a newline character. ::
>>> print(re.search('}$', '{block}'))
>>> print(re.search('}$', '{block}'))
#doctest: +ELLIPSIS
<
_sre
.
SRE_Match
object
at
0x
...
>
<
_sre
.
SRE_Match
object
at
0x
...
>
>>> print(re.search('}$', '{block} '))
>>> print(re.search('}$', '{block} '))
None
None
>>> print(re.search('}$', '{block}\n'))
>>> print(re.search('}$', '{block}\n'))
#doctest: +ELLIPSIS
<
_sre
.
SRE_Match
object
at
0x
...
>
<
_sre
.
SRE_Match
object
at
0x
...
>
To match a literal ``'$'``, use ``\$`` or enclose it inside a character class,
To match a literal ``'$'``, use ``\$`` or enclose it inside a character class,
...
@@ -723,7 +723,7 @@ given location, they can obviously be matched an infinite number of times.
...
@@ -723,7 +723,7 @@ given location, they can obviously be matched an infinite number of times.
match when it's contained inside another word. ::
match when it's contained inside another word. ::
>>> p = re.compile(r'\bclass\b')
>>> p = re.compile(r'\bclass\b')
>>> print(p.search('no class at all'))
>>> print(p.search('no class at all'))
#doctest: +ELLIPSIS
<
_sre
.
SRE_Match
object
at
0x
...
>
<
_sre
.
SRE_Match
object
at
0x
...
>
>>> print(p.search('the declassified algorithm'))
>>> print(p.search('the declassified algorithm'))
None
None
...
@@ -741,7 +741,7 @@ given location, they can obviously be matched an infinite number of times.
...
@@ -741,7 +741,7 @@ given location, they can obviously be matched an infinite number of times.
>>> p = re.compile('\bclass\b')
>>> p = re.compile('\bclass\b')
>>> print(p.search('no class at all'))
>>> print(p.search('no class at all'))
None
None
>>> print(p.search('\b' + 'class' + '\b')
)
>>> print(p.search('\b' + 'class' + '\b')
) #doctest: +ELLIPSIS
<
_sre
.
SRE_Match
object
at
0x
...
>
<
_sre
.
SRE_Match
object
at
0x
...
>
Second, inside a character class, where there's no use for this assertion,
Second, inside a character class, where there's no use for this assertion,
...
@@ -1182,9 +1182,9 @@ compute the desired replacement string and return it.
...
@@ -1182,9 +1182,9 @@ compute the desired replacement string and return it.
In the following example, the replacement function translates decimals into
In the following example, the replacement function translates decimals into
hexadecimal::
hexadecimal::
>>> def hexrepl(
match
):
>>> def hexrepl(
match
):
... "Return the hex string for a decimal number"
... "Return the hex string for a decimal number"
... value = int(
match.group()
)
... value = int(
match.group()
)
... return hex(value)
... return hex(value)
...
...
>>> p = re.compile(r'\d+')
>>> p = re.compile(r'\d+')
...
...
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