678
678
The :class:`RegexObject` class supports the following methods and attributes:
681
.. method:: RegexObject.match(string[, pos[, endpos]])
683
If zero or more characters at the beginning of *string* match this regular
684
expression, return a corresponding :class:`MatchObject` instance. Return
685
``None`` if the string does not match the pattern; note that this is different
686
from a zero-length match.
690
If you want to locate a match anywhere in *string*, use
691
:meth:`~RegexObject.search` instead.
680
.. method:: RegexObject.search(string[, pos[, endpos]])
682
Scan through *string* looking for a location where this regular expression
683
produces a match, and return a corresponding :class:`MatchObject` instance.
684
Return ``None`` if no position in the string matches the pattern; note that this
685
is different from finding a zero-length match at some point in the string.
693
687
The optional second parameter *pos* gives an index in the string where the
694
688
search is to start; it defaults to ``0``. This is not completely equivalent to
700
694
will be as if the string is *endpos* characters long, so only the characters
701
695
from *pos* to ``endpos - 1`` will be searched for a match. If *endpos* is less
702
696
than *pos*, no match will be found, otherwise, if *rx* is a compiled regular
703
expression object, ``rx.match(string, 0, 50)`` is equivalent to
704
``rx.match(string[:50], 0)``.
706
>>> pattern = re.compile("o")
707
>>> pattern.match("dog") # No match as "o" is not at the start of "dog."
708
>>> pattern.match("dog", 1) # Match as "o" is the 2nd character of "dog".
709
<_sre.SRE_Match object at ...>
712
.. method:: RegexObject.search(string[, pos[, endpos]])
714
Scan through *string* looking for a location where this regular expression
715
produces a match, and return a corresponding :class:`MatchObject` instance.
716
Return ``None`` if no position in the string matches the pattern; note that this
717
is different from finding a zero-length match at some point in the string.
697
expression object, ``rx.search(string, 0, 50)`` is equivalent to
698
``rx.search(string[:50], 0)``.
700
>>> pattern = re.compile("d")
701
>>> pattern.search("dog") # Match at index 0
702
<_sre.SRE_Match object at ...>
703
>>> pattern.search("dog", 1) # No match; search doesn't include the "d"
706
.. method:: RegexObject.match(string[, pos[, endpos]])
708
If zero or more characters at the *beginning* of *string* match this regular
709
expression, return a corresponding :class:`MatchObject` instance. Return
710
``None`` if the string does not match the pattern; note that this is different
711
from a zero-length match.
719
713
The optional *pos* and *endpos* parameters have the same meaning as for the
720
:meth:`~RegexObject.match` method.
714
:meth:`~RegexObject.search` method.
718
If you want to locate a match anywhere in *string*, use
719
:meth:`~RegexObject.search` instead.
721
>>> pattern = re.compile("o")
722
>>> pattern.match("dog") # No match as "o" is not at the start of "dog".
723
>>> pattern.match("dog", 1) # Match as "o" is the 2nd character of "dog".
724
<_sre.SRE_Match object at ...>
723
727
.. method:: RegexObject.split(string[, maxsplit=0])