Movatterモバイル変換


[0]ホーム

URL:


Up one LevelPython Library ReferenceContentsModule IndexIndex


4.2.4 Regular Expression Objects

Compiled regular expression objects support the following methods andattributes:

match(string[, pos[, endpos]])
If zero or more characters at the beginning ofstring match this regular expression, return a correspondingMatchObject instance. ReturnNone if the string does not match the pattern; note that this is different from a zero-length match.

Note:If you want to locate a match anywhere instring, usesearch() instead.

The optional second parameterpos gives an index in the string where the search is to start; it defaults to0. This is not completely equivalent to slicing the string; the'^' pattern character matches at the real beginning of the string and at positions just after a newline, but not necessarily at the index where the search is to start.

The optional parameterendpos limits how far the string will be searched; it will be as if the string isendpos characters long, so only the characters frompos toendpos - 1 will be searched for a match. Ifendpos is less thanpos, no match will be found, otherwise, ifrx is a compiled regular expression object,rx.match(string, 0, 50) is equivalent torx.match(string[:50], 0).

search(string[, pos[, endpos]])
Scan throughstring looking for a location where this regular expression produces a match, and return a correspondingMatchObject instance. ReturnNone if no position in the string matches the pattern; note that this is different from finding a zero-length match at some point in the string.

The optionalpos andendpos parameters have the same meaning as for thematch() method.

split(string[, maxsplit = 0])
Identical to thesplit() function, using the compiled pattern.

findall(string[, pos[, endpos]])
Identical to thefindall() function, using the compiled pattern.

finditer(string[, pos[, endpos]])
Identical to thefinditer() function, using the compiled pattern.

sub(repl, string[, count = 0])
Identical to thesub() function, using the compiled pattern.

subn(repl, string[, count = 0])
Identical to thesubn() function, using the compiled pattern.

flags
The flags argument used when the RE object was compiled, or0 if no flags were provided.

groupindex
A dictionary mapping any symbolic group names defined by(?P<id>) to group numbers. The dictionary is empty if nosymbolic groups were used in the pattern.

pattern
The pattern string from which the RE object was compiled.


Up one LevelPython Library ReferenceContentsModule IndexIndex

Release 2.5.2, documentation updated on 21st February, 2008.
SeeAbout this document... for information on suggesting changes.
[8]ページ先頭

©2009-2025 Movatter.jp