~ubuntu-branches/ubuntu/natty/python2.6/natty-security

« back to all changes in this revision

Viewing changes to Doc/library/re.rst

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2010-06-24 00:31:14 UTC
  • mfrom: (10.1.18 sid)
  • Revision ID: james.westby@ubuntu.com-20100624003114-jmwmbudlpucl6ip3
Tags: 2.6.5+20100616-1ubuntu1
* Merge from Debian Unstable.  Remaining Ubuntu changes:
  - Add new symbols to libpython.symbols.in
  - Re-enable the profiled build on all architectures
  - Priority for python2.6-minimal is required instead of optional
  - python2.6-minimal and python2.6 Conflict python-central
    (<< 0.6.11ubuntu6)

Show diffs side-by-side

added added

removed removed

Lines of Context:
677
677
 
678
678
   The :class:`RegexObject` class supports the following methods and attributes:
679
679
 
680
 
 
681
 
   .. method:: RegexObject.match(string[, pos[, endpos]])
682
 
 
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.
687
 
 
688
 
      .. note::
689
 
 
690
 
         If you want to locate a match anywhere in *string*, use
691
 
         :meth:`~RegexObject.search` instead.
 
680
   .. method:: RegexObject.search(string[, pos[, endpos]])
 
681
 
 
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.
692
686
 
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)``.
705
 
 
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 ...>
710
 
 
711
 
 
712
 
   .. method:: RegexObject.search(string[, pos[, endpos]])
713
 
 
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)``.
 
699
 
 
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"
 
704
 
 
705
 
 
706
   .. method:: RegexObject.match(string[, pos[, endpos]])
 
707
 
 
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.
718
712
 
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.
 
715
 
 
716
      .. note::
 
717
 
 
718
         If you want to locate a match anywhere in *string*, use
 
719
         :meth:`~RegexObject.search` instead.
 
720
 
 
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 ...>
721
725
 
722
726
 
723
727
   .. method:: RegexObject.split(string[, maxsplit=0])