[Python-modules-commits] [python-regex] 01/05: Import python-regex_0.1.20160110.orig.tar.gz

Sandro Tosi morph at moszumanska.debian.org
Thu Jan 28 23:26:22 UTC 2016


This is an automated email from the git hooks/post-receive script.

morph pushed a commit to branch master
in repository python-regex.

commit a5dc895f7448f752c98712dbea183645e19eb01a
Author: Sandro Tosi <morph at debian.org>
Date:   Thu Jan 28 23:18:17 2016 +0000

    Import python-regex_0.1.20160110.orig.tar.gz
---
 PKG-INFO               |  998 ++++++++++++----------
 Python2/_regex.c       | 2152 ++++++++++++++++++++++++++++++++++++------------
 Python2/_regex.h       |  171 ++--
 Python2/_regex_core.py |  222 ++++-
 Python2/regex.py       |  103 ++-
 Python2/test_regex.py  |  368 ++++++---
 Python3/_regex.c       | 2152 ++++++++++++++++++++++++++++++++++++------------
 Python3/_regex.h       |  171 ++--
 Python3/_regex_core.py |  222 ++++-
 Python3/regex.py       |  114 +--
 Python3/test_regex.py  |  372 ++++++---
 docs/Features.html     | 1001 +++++++++++-----------
 docs/Features.rst      | 1938 +++++++++++++++++++++++--------------------
 setup.py               |    2 +-
 14 files changed, 6579 insertions(+), 3407 deletions(-)

diff --git a/PKG-INFO b/PKG-INFO
index 34f1091..f3ac398 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: regex
-Version: 2015.07.19
+Version: 2016.01.10
 Summary: Alternative regular expression module, to replace re.
 Home-page: https://bitbucket.org/mrabarnett/mrab-regex
 Author: Matthew Barnett
@@ -18,33 +18,37 @@ Description: Introduction
         
         This module has 2 behaviours:
         
-        **Version 0** behaviour (old behaviour, compatible with the current re module):
+        * **Version 0** behaviour (old behaviour, compatible with the current re module):
         
-            Indicated by the ``VERSION0`` or ``V0`` flag, or ``(?V0)`` in the pattern.
+          * Indicated by the ``VERSION0`` or ``V0`` flag, or ``(?V0)`` in the pattern.
         
-            ``.split`` won't split a string at a zero-width match.
+          * Zero-width matches are handled like in the re module:
         
-            Zero-width matches are handled like in the re module.
+            * ``.split`` won't split a string at a zero-width match.
         
-            Inline flags apply to the entire pattern, and they can't be turned off.
+            * ``.sub`` will advance by one character after a zero-width match.
         
-            Only simple sets are supported.
+          * Inline flags apply to the entire pattern, and they can't be turned off.
         
-            Case-insensitive matches in Unicode use simple case-folding by default.
+          * Only simple sets are supported.
         
-        **Version 1** behaviour (new behaviour, different from the current re module):
+          * Case-insensitive matches in Unicode use simple case-folding by default.
         
-            Indicated by the ``VERSION1`` or ``V1`` flag, or ``(?V1)`` in the pattern.
+        * **Version 1** behaviour (new behaviour, different from the current re module):
         
-            ``.split`` will split a string at a zero-width match.
+          * Indicated by the ``VERSION1`` or ``V1`` flag, or ``(?V1)`` in the pattern.
         
-            Zero-width matches are handled like in Perl and PCRE.
+          * Zero-width matches are handled like in Perl and PCRE:
         
-            Inline flags apply to the end of the group or pattern, and they can be turned off.
+            * ``.split`` will split a string at a zero-width match.
         
-            Nested sets and set operations are supported.
+            * ``.sub`` will handle zero-width matches correctly.
         
-            Case-insensitive matches in Unicode use full case-folding by default.
+          * Inline flags apply to the end of the group or pattern, and they can be turned off.
+        
+          * Nested sets and set operations are supported.
+        
+          * Case-insensitive matches in Unicode use full case-folding by default.
         
         If no version is specified, the regex module will default to ``regex.DEFAULT_VERSION``. In the short term this will be ``VERSION0``, but in the longer term it will be ``VERSION1``.
         
@@ -64,21 +68,21 @@ Description: Introduction
         
         For example, the pattern ``[[a-z]--[aeiou]]`` is treated in the version 0 behaviour (simple sets, compatible with the re module) as:
         
-            Set containing "[" and the letters "a" to "z"
+        * Set containing "[" and the letters "a" to "z"
         
-            Literal "--"
+        * Literal "--"
         
-            Set containing letters "a", "e", "i", "o", "u"
+        * Set containing letters "a", "e", "i", "o", "u"
         
         but in the version 1 behaviour (nested sets, enhanced behaviour) as:
         
-            Set which is:
+        * Set which is:
         
-                Set containing the letters "a" to "z"
+          * Set containing the letters "a" to "z"
         
-            but excluding:
+        * but excluding:
         
-                Set containing the letters "a", "e", "i", "o", "u"
+          * Set containing the letters "a", "e", "i", "o", "u"
         
         Version 0 behaviour: only simple sets are supported.
         
@@ -91,7 +95,7 @@ Description: Introduction
         
         The scoped flags are: ``FULLCASE``, ``IGNORECASE``, ``MULTILINE``, ``DOTALL``, ``VERBOSE``, ``WORD``.
         
-        The global flags are: ``ASCII``, ``BESTMATCH``, ``ENHANCEMATCH``, ``LOCALE``, ``REVERSE``, ``UNICODE``, ``VERSION0``, ``VERSION1``.
+        The global flags are: ``ASCII``, ``BESTMATCH``, ``ENHANCEMATCH``, ``LOCALE``, ``POSIX``, ``REVERSE``, ``UNICODE``, ``VERSION0``, ``VERSION1``.
         
         If neither the ``ASCII``, ``LOCALE`` nor ``UNICODE`` flag is specified, it will default to ``UNICODE`` if the regex pattern is a Unicode string and ``ASCII`` if it's a bytestring.
         
@@ -110,15 +114,15 @@ Description: Introduction
         
         Group numbers will be reused across different branches of a branch reset, eg. ``(?|(first)|(second))`` has only group 1. If capture groups have different group names then they will, of course, have different group numbers, eg. ``(?|(?P<foo>first)|(?P<bar>second))`` has group 1 ("foo") and group 2 ("bar").
         
-        In the regex ``(\s+)(?|(?P<foo>[A-Z]+)|(\w+) (?<foo>[0-9]+)`` there are 2 groups:
+        In the regex ``(\s+)(?|(?P<foo>[A-Z]+)|(\w+) (?P<foo>[0-9]+)`` there are 2 groups:
         
-        1. ``(\s+)`` is group 1.
+        * ``(\s+)`` is group 1.
         
-        2. ``(?P<foo>[A-Z]+)`` is group 2, also called "foo".
+        * ``(?P<foo>[A-Z]+)`` is group 2, also called "foo".
         
-        3. ``(\w+)`` is group 2 because of the branch reset.
+        * ``(\w+)`` is group 2 because of the branch reset.
         
-        4. ``(?<foo>[0-9]+)`` is group 2 because it's called "foo".
+        * ``(?P<foo>[0-9]+)`` is group 2 because it's called "foo".
         
         If you want to prevent ``(\w+)`` from being group 2, you need to name it (different name, different group number).
         
@@ -144,633 +148,753 @@ Description: Introduction
         
         The issue numbers relate to the Python bug tracker, except where listed as "Hg issue".
         
+        * Added support for lookaround in conditional pattern (Hg issue 163)
+        
+          The test of a conditional pattern can now be a lookaround.
+        
+          Examples:
+        
+          .. sourcecode:: python
+        
+            >>> regex.match(r'(?(?=\d)\d+|\w+)', '123abc')
+            <regex.Match object; span=(0, 3), match='123'>
+            >>> regex.match(r'(?(?=\d)\d+|\w+)', 'abc123')
+            <regex.Match object; span=(0, 6), match='abc123'>
+        
+          This is not quite the same as putting a lookaround in the first branch of a pair of alternatives.
+        
+          Examples:
+        
+          .. sourcecode:: python
+        
+            >>> print(regex.match(r'(?:(?=\d)\d+\b|\w+)', '123abc'))
+            <regex.Match object; span=(0, 6), match='123abc'>
+            >>> print(regex.match(r'(?(?=\d)\d+\b|\w+)', '123abc'))
+            None
+        
+          In the first example, the lookaround matched, but the remainder of the first branch failed to match, and so the second branch was attempted, whereas in the second example, the lookaround matched, and the first branch failed to match, but the second branch was **not** attempted.
+        
+        * Added POSIX matching (leftmost longest) (Hg issue 150)
+        
+          The POSIX standard for regex is to return the leftmost longest match. This can be turned on using the ``POSIX`` flag (``(?p)``).
+        
+          Examples:
+        
+          .. sourcecode:: python
+        
+            >>> # Normal matching.
+            >>> regex.search(r'Mr|Mrs', 'Mrs')
+            <regex.Match object; span=(0, 2), match='Mr'>
+            >>> regex.search(r'one(self)?(selfsufficient)?', 'oneselfsufficient')
+            <regex.Match object; span=(0, 7), match='oneself'>
+            >>> # POSIX matching.
+            >>> regex.search(r'(?p)Mr|Mrs', 'Mrs')
+            <regex.Match object; span=(0, 3), match='Mrs'>
+            >>> regex.search(r'(?p)one(self)?(selfsufficient)?', 'oneselfsufficient')
+            <regex.Match object; span=(0, 17), match='oneselfsufficient'>
+        
+          Note that it will take longer to find matches because when it finds a match at a certain position, it won't return that immediately, but will keep looking to see if there's another longer match there.
+        
+        * Added ``(?(DEFINE)...)`` (Hg issue 152)
+        
+          If there's no group called "DEFINE", then ... will be ignored, but any group definitions within it will be available.
+        
+          Examples:
+        
+          .. sourcecode:: python
+        
+            >>> regex.search(r'(?(DEFINE)(?P<quant>\d+)(?P<item>\w+))(?&quant) (?&item)', '5 elephants')
+            <regex.Match object; span=(0, 11), match='5 elephants'>
+        
+        * Added ``(*PRUNE)``, ``(*SKIP)`` and ``(*FAIL)`` (Hg issue 153)
+        
+          ``(*PRUNE)`` discards the backtracking info up to that point. When used in an atomic group or a lookaround, it won't affect the enclosing pattern.
+        
+          ``(*SKIP)`` is similar to ``(*PRUNE)``, except that it also sets where in the text the next attempt to match will start. When used in an atomic group or a lookaround, it won't affect the enclosing pattern.
+        
+          ``(*FAIL)`` causes immediate backtracking. ``(*F)`` is a permitted abbreviation.
+        
+        * Added ``\K`` (Hg issue 151)
+        
+          Keeps the part of the entire match after the position where ``\K`` occurred; the part before it is discarded.
+        
+          It does not affect what capture groups return.
+        
+          Examples:
+        
+          .. sourcecode:: python
+        
+            >>> m = regex.search(r'(\w\w\K\w\w\w)', 'abcdef')
+            >>> m[0]
+            'cde'
+            >>> m[1]
+            'abcde'
+            >>>
+            >>> m = regex.search(r'(?r)(\w\w\K\w\w\w)', 'abcdef')
+            >>> m[0]
+            'bc'
+            >>> m[1]
+            'bcdef'
+        
         * Added capture subscripting for ``expandf`` and ``subf``/``subfn`` (Hg issue 133) **(Python 2.6 and above)**
         
-            You can now use subscripting to get the captures of a repeated capture group.
+          You can now use subscripting to get the captures of a repeated capture group.
+        
+          Examples:
         
-            Examples::
+          .. sourcecode:: python
         
-                >>> import regex
-                >>> m = regex.match(r"(\w)+", "abc")
-                >>> m.expandf("{1}")
-                'c'
-                >>> m.expandf("{1[0]} {1[1]} {1[2]}")
-                'a b c'
-                >>> m.expandf("{1[-1]} {1[-2]} {1[-3]}")
-                'c b a'
-                >>>
-                >>> m = regex.match(r"(?P<letter>\w)+", "abc")
-                >>> m.expandf("{letter}")
-                'c'
-                >>> m.expandf("{letter[0]} {letter[1]} {letter[2]}")
-                'a b c'
-                >>> m.expandf("{letter[-1]} {letter[-2]} {letter[-3]}")
-                'c b a'
+            >>> m = regex.match(r"(\w)+", "abc")
+            >>> m.expandf("{1}")
+            'c'
+            >>> m.expandf("{1[0]} {1[1]} {1[2]}")
+            'a b c'
+            >>> m.expandf("{1[-1]} {1[-2]} {1[-3]}")
+            'c b a'
+            >>>
+            >>> m = regex.match(r"(?P<letter>\w)+", "abc")
+            >>> m.expandf("{letter}")
+            'c'
+            >>> m.expandf("{letter[0]} {letter[1]} {letter[2]}")
+            'a b c'
+            >>> m.expandf("{letter[-1]} {letter[-2]} {letter[-3]}")
+            'c b a'
         
-        * Added support for referring to a group by number using (?P=...).
+        * Added support for referring to a group by number using ``(?P=...)``.
         
-            This is in addition to the existing ``\g<...>``.
+          This is in addition to the existing ``\g<...>``.
         
         * Fixed the handling of locale-sensitive regexes.
         
-            The ``LOCALE`` flag is intended for legacy code and has limited support. You're still recommended to use Unicode instead.
+          The ``LOCALE`` flag is intended for legacy code and has limited support. You're still recommended to use Unicode instead.
         
         * Added partial matches (Hg issue 102)
         
-            A partial match is one that matches up to the end of string, but that string has been truncated and you want to know whether a complete match could be possible if the string had not been truncated.
+          A partial match is one that matches up to the end of string, but that string has been truncated and you want to know whether a complete match could be possible if the string had not been truncated.
         
-            Partial matches are supported by ``match``, ``search``, ``fullmatch`` and ``finditer`` with the ``partial`` keyword argument.
+          Partial matches are supported by ``match``, ``search``, ``fullmatch`` and ``finditer`` with the ``partial`` keyword argument.
         
-            Match objects have a ``partial`` attribute, which is ``True`` if it's a partial match.
+          Match objects have a ``partial`` attribute, which is ``True`` if it's a partial match.
         
-            For example, if you wanted a user to enter a 4-digit number and check it character by character as it was being entered:
+          For example, if you wanted a user to enter a 4-digit number and check it character by character as it was being entered:
         
-                >>> pattern = regex.compile(r'\d{4}')
+          .. sourcecode:: python
         
-                >>> # Initially, nothing has been entered:
-                >>> print(pattern.fullmatch('', partial=True))
-                <regex.Match object; span=(0, 0), match='', partial=True>
+            >>> pattern = regex.compile(r'\d{4}')
         
-                >>> # An empty string is OK, but it's only a partial match.
-                >>> # The user enters a letter:
-                >>> print(pattern.fullmatch('a', partial=True))
-                None
-                >>> # It'll never match.
+            >>> # Initially, nothing has been entered:
+            >>> print(pattern.fullmatch('', partial=True))
+            <regex.Match object; span=(0, 0), match='', partial=True>
         
-                >>> # The user deletes that and enters a digit:
-                >>> print(pattern.fullmatch('1', partial=True))
-                <regex.Match object; span=(0, 1), match='1', partial=True>
-                >>> # It matches this far, but it's only a partial match.
+            >>> # An empty string is OK, but it's only a partial match.
+            >>> # The user enters a letter:
+            >>> print(pattern.fullmatch('a', partial=True))
+            None
+            >>> # It'll never match.
         
-                >>> # The user enters 2 more digits:
-                >>> print(pattern.fullmatch('123', partial=True))
-                <regex.Match object; span=(0, 3), match='123', partial=True>
-                >>> # It matches this far, but it's only a partial match.
+            >>> # The user deletes that and enters a digit:
+            >>> print(pattern.fullmatch('1', partial=True))
+            <regex.Match object; span=(0, 1), match='1', partial=True>
+            >>> # It matches this far, but it's only a partial match.
         
-                >>> # The user enters another digit:
-                >>> print(pattern.fullmatch('1234', partial=True))
-                <regex.Match object; span=(0, 4), match='1234'>
-                >>> # It's a complete match.
+            >>> # The user enters 2 more digits:
+            >>> print(pattern.fullmatch('123', partial=True))
+            <regex.Match object; span=(0, 3), match='123', partial=True>
+            >>> # It matches this far, but it's only a partial match.
         
-                >>> # If the user enters another digit:
-                >>> print(pattern.fullmatch('12345', partial=True))
-                None
-                >>> # It's no longer a match.
+            >>> # The user enters another digit:
+            >>> print(pattern.fullmatch('1234', partial=True))
+            <regex.Match object; span=(0, 4), match='1234'>
+            >>> # It's a complete match.
         
-                >>> # This is a partial match:
-                >>> pattern.match('123', partial=True).partial
-                True
+            >>> # If the user enters another digit:
+            >>> print(pattern.fullmatch('12345', partial=True))
+            None
+            >>> # It's no longer a match.
         
-                >>> # This is a complete match:
-                >>> pattern.match('1233', partial=True).partial
-                False
+            >>> # This is a partial match:
+            >>> pattern.match('123', partial=True).partial
+            True
+        
+            >>> # This is a complete match:
+            >>> pattern.match('1233', partial=True).partial
+            False
         
         * ``*`` operator not working correctly with sub() (Hg issue 106)
         
-            Sometimes it's not clear how zero-width matches should be handled. For example, should ``.*`` match 0 characters directly after matching >0 characters?
+          Sometimes it's not clear how zero-width matches should be handled. For example, should ``.*`` match 0 characters directly after matching >0 characters?
+        
+          Most regex implementations follow the lead of Perl (PCRE), but the re module sometimes doesn't. The Perl behaviour appears to be the most common (and the re module is sometimes definitely wrong), so in version 1 the regex module follows the Perl behaviour, whereas in version 0 it follows the legacy re behaviour.
         
-            Most regex implementations follow the lead of Perl (PCRE), but the re module sometimes doesn't. The Perl behaviour appears to be the most common (and the re module is sometimes definitely wrong), so in version 1 the regex module follows the Perl behaviour, whereas in version 0 it follows the legacy re behaviour.
+          Examples:
         
-            Examples::
+          .. sourcecode:: python
         
-                # Version 0 behaviour (like re)
-                >>> regex.sub('(?V0).*', 'x', 'test')
-                'x'
-                >>> regex.sub('(?V0).*?', '|', 'test')
-                '|t|e|s|t|'
+            >>> # Version 0 behaviour (like re)
+            >>> regex.sub('(?V0).*', 'x', 'test')
+            'x'
+            >>> regex.sub('(?V0).*?', '|', 'test')
+            '|t|e|s|t|'
         
-                # Version 1 behaviour (like Perl)
-                >>> regex.sub('(?V1).*', 'x', 'test')
-                'xx'
-                >>> regex.sub('(?V1).*?', '|', 'test')
-                '|||||||||'
+            >>> # Version 1 behaviour (like Perl)
+            >>> regex.sub('(?V1).*', 'x', 'test')
+            'xx'
+            >>> regex.sub('(?V1).*?', '|', 'test')
+            '|||||||||'
         
         * re.group() should never return a bytearray (issue #18468)
         
-            For compatibility with the re module, the regex module returns all matching bytestrings as ``bytes``, starting from Python 3.4.
+          For compatibility with the re module, the regex module returns all matching bytestrings as ``bytes``, starting from Python 3.4.
         
-            Examples::
+          Examples:
         
-                >>> # Python 3.4 and later
-                >>> import regex
-                >>> regex.match(b'.', bytearray(b'a')).group()
-                b'a'
+          .. sourcecode:: python
         
-                >>> # Python 3.1-3.3
-                >>> import regex
-                >>> regex.match(b'.', bytearray(b'a')).group()
-                bytearray(b'a')
+            >>> # Python 3.4 and later
+            >>> regex.match(b'.', bytearray(b'a')).group()
+            b'a'
+        
+            >>> # Python 3.1-3.3
+            >>> regex.match(b'.', bytearray(b'a')).group()
+            bytearray(b'a')
         
         * Added ``capturesdict`` (Hg issue 86)
         
-            ``capturesdict`` is a combination of ``groupdict`` and ``captures``:
+          ``capturesdict`` is a combination of ``groupdict`` and ``captures``:
+        
+          ``groupdict`` returns a dict of the named groups and the last capture of those groups.
         
-            ``groupdict`` returns a dict of the named groups and the last capture of those groups.
+          ``captures`` returns a list of all the captures of a group
         
-            ``captures`` returns a list of all the captures of a group
+          ``capturesdict`` returns a dict of the named groups and lists of all the captures of those groups.
         
-            ``capturesdict`` returns a dict of the named groups and lists of all the captures of those groups.
+          Examples:
         
-            Examples::
+          .. sourcecode:: python
         
-                >>> import regex
-                >>> m = regex.match(r"(?:(?P<word>\w+) (?P<digits>\d+)\n)+", "one 1\ntwo 2\nthree 3\n")
-                >>> m.groupdict()
-                {'word': 'three', 'digits': '3'}
-                >>> m.captures("word")
-                ['one', 'two', 'three']
-                >>> m.captures("digits")
-                ['1', '2', '3']
-                >>> m.capturesdict()
-                {'word': ['one', 'two', 'three'], 'digits': ['1', '2', '3']}
+            >>> m = regex.match(r"(?:(?P<word>\w+) (?P<digits>\d+)\n)+", "one 1\ntwo 2\nthree 3\n")
+            >>> m.groupdict()
+            {'word': 'three', 'digits': '3'}
+            >>> m.captures("word")
+            ['one', 'two', 'three']
+            >>> m.captures("digits")
+            ['1', '2', '3']
+            >>> m.capturesdict()
+            {'word': ['one', 'two', 'three'], 'digits': ['1', '2', '3']}
         
         * Allow duplicate names of groups (Hg issue 87)
         
-            Group names can now be duplicated.
-        
-            Examples::
-        
-                >>> import regex
-                >>>
-                >>> # With optional groups:
-                >>>
-                >>> # Both groups capture, the second capture 'overwriting' the first.
-                >>> m = regex.match(r"(?P<item>\w+)? or (?P<item>\w+)?", "first or second")
-                >>> m.group("item")
-                'second'
-                >>> m.captures("item")
-                ['first', 'second']
-                >>> # Only the second group captures.
-                >>> m = regex.match(r"(?P<item>\w+)? or (?P<item>\w+)?", " or second")
-                >>> m.group("item")
-                'second'
-                >>> m.captures("item")
-                ['second']
-                >>> # Only the first group captures.
-                >>> m = regex.match(r"(?P<item>\w+)? or (?P<item>\w+)?", "first or ")
-                >>> m.group("item")
-                'first'
-                >>> m.captures("item")
-                ['first']
-                >>>
-                >>> # With mandatory groups:
-                >>>
-                >>> # Both groups capture, the second capture 'overwriting' the first.
-                >>> m = regex.match(r"(?P<item>\w*) or (?P<item>\w*)?", "first or second")
-                >>> m.group("item")
-                'second'
-                >>> m.captures("item")
-                ['first', 'second']
-                >>> # Again, both groups capture, the second capture 'overwriting' the first.
-                >>> m = regex.match(r"(?P<item>\w*) or (?P<item>\w*)", " or second")
-                >>> m.group("item")
-                'second'
-                >>> m.captures("item")
-                ['', 'second']
-                >>> # And yet again, both groups capture, the second capture 'overwriting' the first.
-                >>> m = regex.match(r"(?P<item>\w*) or (?P<item>\w*)", "first or ")
-                >>> m.group("item")
-                ''
-                >>> m.captures("item")
-                ['first', '']
+          Group names can now be duplicated.
+        
+          Examples:
+        
+          .. sourcecode:: python
+        
+            >>> # With optional groups:
+            >>>
+            >>> # Both groups capture, the second capture 'overwriting' the first.
+            >>> m = regex.match(r"(?P<item>\w+)? or (?P<item>\w+)?", "first or second")
+            >>> m.group("item")
+            'second'
+            >>> m.captures("item")
+            ['first', 'second']
+            >>> # Only the second group captures.
+            >>> m = regex.match(r"(?P<item>\w+)? or (?P<item>\w+)?", " or second")
+            >>> m.group("item")
+            'second'
+            >>> m.captures("item")
+            ['second']
+            >>> # Only the first group captures.
+            >>> m = regex.match(r"(?P<item>\w+)? or (?P<item>\w+)?", "first or ")
+            >>> m.group("item")
+            'first'
+            >>> m.captures("item")
+            ['first']
+            >>>
+            >>> # With mandatory groups:
+            >>>
+            >>> # Both groups capture, the second capture 'overwriting' the first.
+            >>> m = regex.match(r"(?P<item>\w*) or (?P<item>\w*)?", "first or second")
+            >>> m.group("item")
+            'second'
+            >>> m.captures("item")
+            ['first', 'second']
+            >>> # Again, both groups capture, the second capture 'overwriting' the first.
+            >>> m = regex.match(r"(?P<item>\w*) or (?P<item>\w*)", " or second")
+            >>> m.group("item")
+            'second'
+            >>> m.captures("item")
+            ['', 'second']
+            >>> # And yet again, both groups capture, the second capture 'overwriting' the first.
+            >>> m = regex.match(r"(?P<item>\w*) or (?P<item>\w*)", "first or ")
+            >>> m.group("item")
+            ''
+            >>> m.captures("item")
+            ['first', '']
         
         * Added ``fullmatch`` (issue #16203)
         
-            ``fullmatch`` behaves like ``match``, except that it must match all of the string.
-        
-            Examples::
-        
-                >>> import regex
-                >>> print(regex.fullmatch(r"abc", "abc").span())
-                (0, 3)
-                >>> print(regex.fullmatch(r"abc", "abcx"))
-                None
-                >>> print(regex.fullmatch(r"abc", "abcx", endpos=3).span())
-                (0, 3)
-                >>> print(regex.fullmatch(r"abc", "xabcy", pos=1, endpos=4).span())
-                (1, 4)
-                >>>
-                >>> regex.match(r"a.*?", "abcd").group(0)
-                'a'
-                >>> regex.fullmatch(r"a.*?", "abcd").group(0)
-                'abcd'
+          ``fullmatch`` behaves like ``match``, except that it must match all of the string.
+        
+          Examples:
+        
+          .. sourcecode:: python
+        
+            >>> print(regex.fullmatch(r"abc", "abc").span())
+            (0, 3)
+            >>> print(regex.fullmatch(r"abc", "abcx"))
+            None
+            >>> print(regex.fullmatch(r"abc", "abcx", endpos=3).span())
+            (0, 3)
+            >>> print(regex.fullmatch(r"abc", "xabcy", pos=1, endpos=4).span())
+            (1, 4)
+            >>>
+            >>> regex.match(r"a.*?", "abcd").group(0)
+            'a'
+            >>> regex.fullmatch(r"a.*?", "abcd").group(0)
+            'abcd'
         
         * Added ``subf`` and ``subfn`` **(Python 2.6 and above)**
         
-            ``subf`` and ``subfn`` are alternatives to ``sub`` and ``subn`` respectively. When passed a replacement string, they treat it as a format string.
+          ``subf`` and ``subfn`` are alternatives to ``sub`` and ``subn`` respectively. When passed a replacement string, they treat it as a format string.
+        
+          Examples:
         
-            Examples::
+          .. sourcecode:: python
         
-                >>> import regex
-                >>> regex.subf(r"(\w+) (\w+)", "{0} => {2} {1}", "foo bar")
-                'foo bar => bar foo'
-                >>> regex.subf(r"(?P<word1>\w+) (?P<word2>\w+)", "{word2} {word1}", "foo bar")
-                'bar foo'
+            >>> regex.subf(r"(\w+) (\w+)", "{0} => {2} {1}", "foo bar")
+            'foo bar => bar foo'
+            >>> regex.subf(r"(?P<word1>\w+) (?P<word2>\w+)", "{word2} {word1}", "foo bar")
+            'bar foo'
         
         * Added ``expandf`` to match object **(Python 2.6 and above)**
         
-            ``expandf`` is an alternative to ``expand``. When passed a replacement string, it treats it as a format string.
+          ``expandf`` is an alternative to ``expand``. When passed a replacement string, it treats it as a format string.
         
-            Examples::
+          Examples:
         
-                >>> import regex
-                >>> m = regex.match(r"(\w+) (\w+)", "foo bar")
-                >>> m.expandf("{0} => {2} {1}")
-                'foo bar => bar foo'
-                >>>
-                >>> m = regex.match(r"(?P<word1>\w+) (?P<word2>\w+)", "foo bar")
-                >>> m.expandf("{word2} {word1}")
-                'bar foo'
+          .. sourcecode:: python
+        
+            >>> m = regex.match(r"(\w+) (\w+)", "foo bar")
+            >>> m.expandf("{0} => {2} {1}")
+            'foo bar => bar foo'
+            >>>
+            >>> m = regex.match(r"(?P<word1>\w+) (?P<word2>\w+)", "foo bar")
+            >>> m.expandf("{word2} {word1}")
+            'bar foo'
         
         * Detach searched string
         
-            A match object contains a reference to the string that was searched, via its ``string`` attribute. The match object now has a ``detach_string`` method that will 'detach' that string, making it available for garbage collection (this might save valuable memory if that string is very large).
+          A match object contains a reference to the string that was searched, via its ``string`` attribute. The match object now has a ``detach_string`` method that will 'detach' that string, making it available for garbage collection (this might save valuable memory if that string is very large).
+        
+          Example:
         
-            Example::
+          .. sourcecode:: python
         
-                >>> import regex
-                >>> m = regex.search(r"\w+", "Hello world")
-                >>> print(m.group())
-                Hello
-                >>> print(m.string)
-                Hello world
-                >>> m.detach_string()
-                >>> print(m.group())
-                Hello
-                >>> print(m.string)
-                None
+            >>> m = regex.search(r"\w+", "Hello world")
+            >>> print(m.group())
+            Hello
+            >>> print(m.string)
+            Hello world
+            >>> m.detach_string()
+            >>> print(m.group())
+            Hello
+            >>> print(m.string)
+            None
         
         * Characters in a group name (issue #14462)
         
-            A group name can now contain the same characters as an identifier. These are different in Python 2 and Python 3.
+          A group name can now contain the same characters as an identifier. These are different in Python 2 and Python 3.
         
         * Recursive patterns (Hg issue 27)
         
-            Recursive and repeated patterns are supported.
+          Recursive and repeated patterns are supported.
+        
+          ``(?R)`` or ``(?0)`` tries to match the entire regex recursively. ``(?1)``, ``(?2)``, etc, try to match the relevant capture group.
         
-            ``(?R)`` or ``(?0)`` tries to match the entire regex recursively. ``(?1)``, ``(?2)``, etc, try to match the relevant capture group.
+          ``(?&name)`` tries to match the named capture group.
         
-            ``(?&name)`` tries to match the named capture group.
+          Examples:
         
-            Examples::
+          .. sourcecode:: python
         
-                >>> regex.match(r"(Tarzan|Jane) loves (?1)", "Tarzan loves Jane").groups()
-                ('Tarzan',)
-                >>> regex.match(r"(Tarzan|Jane) loves (?1)", "Jane loves Tarzan").groups()
-                ('Jane',)
+            >>> regex.match(r"(Tarzan|Jane) loves (?1)", "Tarzan loves Jane").groups()
+            ('Tarzan',)
+            >>> regex.match(r"(Tarzan|Jane) loves (?1)", "Jane loves Tarzan").groups()
+            ('Jane',)
         
-                >>> m = regex.search(r"(\w)(?:(?R)|(\w?))\1", "kayak")
-                >>> m.group(0, 1, 2)
-                ('kayak', 'k', None)
+            >>> m = regex.search(r"(\w)(?:(?R)|(\w?))\1", "kayak")
+            >>> m.group(0, 1, 2)
+            ('kayak', 'k', None)
         
-            The first two examples show how the subpattern within the capture group is reused, but is _not_ itself a capture group. In other words, ``"(Tarzan|Jane) loves (?1)"`` is equivalent to ``"(Tarzan|Jane) loves (?:Tarzan|Jane)"``.
+          The first two examples show how the subpattern within the capture group is reused, but is _not_ itself a capture group. In other words, ``"(Tarzan|Jane) loves (?1)"`` is equivalent to ``"(Tarzan|Jane) loves (?:Tarzan|Jane)"``.
         
-            It's possible to backtrack into a recursed or repeated group.
+          It's possible to backtrack into a recursed or repeated group.
         
-            You can't call a group if there is more than one group with that group name or group number (``"ambiguous group reference"``). For example, ``(?P<foo>\w+) (?P<foo>\w+) (?&foo)?`` has 2 groups called "foo" (both group 1) and ``(?|([A-Z]+)|([0-9]+)) (?1)?`` has 2 groups with group number 1.
+          You can't call a group if there is more than one group with that group name or group number (``"ambiguous group reference"``). For example, ``(?P<foo>\w+) (?P<foo>\w+) (?&foo)?`` has 2 groups called "foo" (both group 1) and ``(?|([A-Z]+)|([0-9]+)) (?1)?`` has 2 groups with group number 1.
         
-            The alternative forms ``(?P>name)`` and ``(?P&name)`` are also supported.
+          The alternative forms ``(?P>name)`` and ``(?P&name)`` are also supported.
         
         * repr(regex) doesn't include actual regex (issue #13592)
         
-            The repr of a compiled regex is now in the form of a eval-able string. For example::
+          The repr of a compiled regex is now in the form of a eval-able string. For example:
         
-                >>> r = regex.compile("foo", regex.I)
-                >>> repr(r)
-                "regex.Regex('foo', flags=regex.I | regex.V0)"
-                >>> r
-                regex.Regex('foo', flags=regex.I | regex.V0)
+          .. sourcecode:: python
         
-            The regex module has Regex as an alias for the 'compile' function.
+            >>> r = regex.compile("foo", regex.I)
+            >>> repr(r)
+            "regex.Regex('foo', flags=regex.I | regex.V0)"
+            >>> r
+            regex.Regex('foo', flags=regex.I | regex.V0)
+        
+          The regex module has Regex as an alias for the 'compile' function.
         
         * Improve the repr for regular expression match objects (issue #17087)
         
-            The repr of a match object is now a more useful form. For example::
+          The repr of a match object is now a more useful form. For example:
+        
+          .. sourcecode:: python
         
-                >>> regex.search(r"\d+", "abc012def")
-                <regex.Match object; span=(3, 6), match='012'>
+            >>> regex.search(r"\d+", "abc012def")
+            <regex.Match object; span=(3, 6), match='012'>
         
         * Python lib re cannot handle Unicode properly due to narrow/wide bug (issue #12729)
         
-            The source code of the regex module has been updated to support PEP 393 ("Flexible String Representation"), which is new in Python 3.3.
+          The source code of the regex module has been updated to support PEP 393 ("Flexible String Representation"), which is new in Python 3.3.
         
         * Full Unicode case-folding is supported.
         
-            In version 1 behaviour, the regex module uses full case-folding when performing case-insensitive matches in Unicode.
+          In version 1 behaviour, the regex module uses full case-folding when performing case-insensitive matches in Unicode.
         
-            Examples (in Python 3):
+          Examples (in Python 3):
         
-                >>> regex.match(r"(?iV1)strasse", "stra\N{LATIN SMALL LETTER SHARP S}e").span()
-                (0, 6)
-                >>> regex.match(r"(?iV1)stra\N{LATIN SMALL LETTER SHARP S}e", "STRASSE").span()
-                (0, 7)
+          .. sourcecode:: python
         
-            In version 0 behaviour, it uses simple case-folding for backward compatibility with the re module.
+            >>> regex.match(r"(?iV1)strasse", "stra\N{LATIN SMALL LETTER SHARP S}e").span()
+            (0, 6)
+            >>> regex.match(r"(?iV1)stra\N{LATIN SMALL LETTER SHARP S}e", "STRASSE").span()
+            (0, 7)
+        
+          In version 0 behaviour, it uses simple case-folding for backward compatibility with the re module.
         
         * Approximate "fuzzy" matching (Hg issue 12, Hg issue 41, Hg issue 109)
         
-            Regex usually attempts an exact match, but sometimes an approximate, or "fuzzy", match is needed, for those cases where the text being searched may contain errors in the form of inserted, deleted or substituted characters.
+          Regex usually attempts an exact match, but sometimes an approximate, or "fuzzy", match is needed, for those cases where the text being searched may contain errors in the form of inserted, deleted or substituted characters.
+        
+          A fuzzy regex specifies which types of errors are permitted, and, optionally, either the minimum and maximum or only the maximum permitted number of each type. (You cannot specify only a minimum.)
         
-            A fuzzy regex specifies which types of errors are permitted, and, optionally, either the minimum and maximum or only the maximum permitted number of each type. (You cannot specify only a minimum.)
+          The 3 types of error are:
         
-            The 3 types of error are:
+          * Insertion, indicated by "i"
         
-            * Insertion, indicated by "i"
+          * Deletion, indicated by "d"
         
-            * Deletion, indicated by "d"
+          * Substitution, indicated by "s"
         
-            * Substitution, indicated by "s"
+          In addition, "e" indicates any type of error.
         
-            In addition, "e" indicates any type of error.
+          The fuzziness of a regex item is specified between "{" and "}" after the item.
         
-            The fuzziness of a regex item is specified between "{" and "}" after the item.
+          Examples:
         
-            Examples:
+          * ``foo`` match "foo" exactly
         
-            ``foo`` match "foo" exactly
+          * ``(?:foo){i}`` match "foo", permitting insertions
         
-            ``(?:foo){i}`` match "foo", permitting insertions
+          * ``(?:foo){d}`` match "foo", permitting deletions
         
-            ``(?:foo){d}`` match "foo", permitting deletions
+          * ``(?:foo){s}`` match "foo", permitting substitutions
         
-            ``(?:foo){s}`` match "foo", permitting substitutions
+          * ``(?:foo){i,s}`` match "foo", permitting insertions and substitutions
         
-            ``(?:foo){i,s}`` match "foo", permitting insertions and substitutions
+          * ``(?:foo){e}`` match "foo", permitting errors
         
-            ``(?:foo){e}`` match "foo", permitting errors
+          If a certain type of error is specified, then any type not specified will **not** be permitted.
         
-            If a certain type of error is specified, then any type not specified will **not** be permitted.
+          In the following examples I'll omit the item and write only the fuzziness:
         
-            In the following examples I'll omit the item and write only the fuzziness.
+          * ``{i<=3}`` permit at most 3 insertions, but no other types
         
-            ``{i<=3}`` permit at most 3 insertions, but no other types
+          * ``{d<=3}`` permit at most 3 deletions, but no other types
         
-            ``{d<=3}`` permit at most 3 deletions, but no other types
+          * ``{s<=3}`` permit at most 3 substitutions, but no other types
         
-            ``{s<=3}`` permit at most 3 substitutions, but no other types
+          * ``{i<=1,s<=2}`` permit at most 1 insertion and at most 2 substitutions, but no deletions
         
-            ``{i<=1,s<=2}`` permit at most 1 insertion and at most 2 substitutions, but no deletions
+          * ``{e<=3}`` permit at most 3 errors
         
-            ``{e<=3}`` permit at most 3 errors
+          * ``{1<=e<=3}`` permit at least 1 and at most 3 errors
         
-            ``{1<=e<=3}`` permit at least 1 and at most 3 errors
+          * ``{i<=2,d<=2,e<=3}`` permit at most 2 insertions, at most 2 deletions, at most 3 errors in total, but no substitutions
         
-            ``{i<=2,d<=2,e<=3}`` permit at most 2 insertions, at most 2 deletions, at most 3 errors in total, but no substitutions
+          It's also possible to state the costs of each type of error and the maximum permitted total cost.
         
-            It's also possible to state the costs of each type of error and the maximum permitted total cost.
+          Examples:
         
-            Examples:
+          * ``{2i+2d+1s<=4}`` each insertion costs 2, each deletion costs 2, each substitution costs 1, the total cost must not exceed 4
         
-            ``{2i+2d+1s<=4}`` each insertion costs 2, each deletion costs 2, each substitution costs 1, the total cost must not exceed 4
+          * ``{i<=1,d<=1,s<=1,2i+2d+1s<=4}`` at most 1 insertion, at most 1 deletion, at most 1 substitution; each insertion costs 2, each deletion costs 2, each substitution costs 1, the total cost must not exceed 4
         
-            ``{i<=1,d<=1,s<=1,2i+2d+1s<=4}`` at most 1 insertion, at most 1 deletion, at most 1 substitution; each insertion costs 2, each deletion costs 2, each substitution costs 1, the total cost must not exceed 4
+          You can also use "<" instead of "<=" if you want an exclusive minimum or maximum:
         
-            You can also use "<" instead of "<=" if you want an exclusive minimum or maximum:
+          * ``{e<=3}`` permit up to 3 errors
         
-            ``{e<=3}`` permit up to 3 errors
+          * ``{e<4}`` permit fewer than 4 errors
         
-            ``{e<4}`` permit fewer than 4 errors
+          * ``{0<e<4}`` permit more than 0 but fewer than 4 errors
         
-            ``{0<e<4}`` permit more than 0 but fewer than 4 errors
+          By default, fuzzy matching searches for the first match that meets the given constraints. The ``ENHANCEMATCH`` flag will cause it to attempt to improve the fit (i.e. reduce the number of errors) of the match that it has found.
         
-            By default, fuzzy matching searches for the first match that meets the given constraints. The ``ENHANCEMATCH`` flag will cause it to attempt to improve the fit (i.e. reduce the number of errors) of the match that it has found.
+          The ``BESTMATCH`` flag will make it search for the best match instead.
         
-            The ``BESTMATCH`` flag will make it search for the best match instead.
+          Further examples to note:
         
-            Further examples to note:
+          * ``regex.search("(dog){e}", "cat and dog")[1]`` returns ``"cat"`` because that matches ``"dog"`` with 3 errors, which is within the limit (an unlimited number of errors is permitted).
         
-            ``regex.search("(dog){e}", "cat and dog")[1]`` returns ``"cat"`` because that matches ``"dog"`` with 3 errors, which is within the limit (an unlimited number of errors is permitted).
+          * ``regex.search("(dog){e<=1}", "cat and dog")[1]`` returns ``" dog"`` (with a leading space) because that matches ``"dog"`` with 1 error, which is within the limit (1 error is permitted).
         
-            ``regex.search("(dog){e<=1}", "cat and dog")[1]`` returns ``" dog"`` (with a leading space) because that matches ``"dog"`` with 1 error, which is within the limit (1 error is permitted).
+          * ``regex.search("(?e)(dog){e<=1}", "cat and dog")[1]`` returns ``"dog"`` (without a leading space) because the fuzzy search matches ``" dog"`` with 1 error, which is within the limit (1 error is permitted), and the ``(?e)`` then makes it attempt a better fit.
         
-            ``regex.search("(?e)(dog){e<=1}", "cat and dog")[1]`` returns ``"dog"`` (without a leading space) because the fuzzy search matches ``" dog"`` with 1 error, which is within the limit (1 error is permitted), and the ``(?e)`` then makes it attempt a better fit.
+          In the first two examples there are perfect matches later in the string, but in neither case is it the first possible match.
         
-            In the first two examples there are perfect matches later in the string, but in neither case is it the first possible match.
+          The match object has an attribute ``fuzzy_counts`` which gives the total number of substitutions, insertions and deletions.
         
-            The match object has an attribute ``fuzzy_counts`` which gives the total number of substitutions, insertions and deletions.
+          .. sourcecode:: python
         
-                >>> # A 'raw' fuzzy match:
-                >>> regex.fullmatch(r"(?:cats|cat){e<=1}", "cat").fuzzy_counts
-                (0, 0, 1)
-                >>> # 0 substitutions, 0 insertions, 1 deletion.
+            >>> # A 'raw' fuzzy match:
+            >>> regex.fullmatch(r"(?:cats|cat){e<=1}", "cat").fuzzy_counts
+            (0, 0, 1)
+            >>> # 0 substitutions, 0 insertions, 1 deletion.
         
-                >>> # A better match might be possible if the ENHANCEMATCH flag used:
-                >>> regex.fullmatch(r"(?e)(?:cats|cat){e<=1}", "cat").fuzzy_counts
-                (0, 0, 0)
-                >>> # 0 substitutions, 0 insertions, 0 deletions.
+            >>> # A better match might be possible if the ENHANCEMATCH flag used:
+            >>> regex.fullmatch(r"(?e)(?:cats|cat){e<=1}", "cat").fuzzy_counts
+            (0, 0, 0)
+            >>> # 0 substitutions, 0 insertions, 0 deletions.
         
         * Named lists (Hg issue 11)
         
-            ``\L<name>``
+          ``\L<name>``
         
-            There are occasions where you may want to include a list (actually, a set) of options in a regex.
+          There are occasions where you may want to include a list (actually, a set) of options in a regex.
         
-            One way is to build the pattern like this::
+          One way is to build the pattern like this:
         
-                p = regex.compile(r"first|second|third|fourth|fifth")
+          .. sourcecode:: python
         
-            but if the list is large, parsing the resulting regex can take considerable time, and care must also be taken that the strings are properly escaped if they contain any character that has a special meaning in a regex, and that if there is a shorter string that occurs initially in a longer string that the longer string is listed before the shorter one, for example, "cats" before "cat".
+            >>> p = regex.compile(r"first|second|third|fourth|fifth")
         
-            The new alternative is to use a named list::
+          but if the list is large, parsing the resulting regex can take considerable time, and care must also be taken that the strings are properly escaped if they contain any character that has a special meaning in a regex, and that if there is a shorter string that occurs initially in a longer string that the longer string is listed before the shorter one, for example, "cats" before "cat".
         
-                option_set = ["first", "second", "third", "fourth", "fifth"]
-                p = regex.compile(r"\L<options>", options=option_set)
+          The new alternative is to use a named list:
         
-            The order of the items is irrelevant, they are treated as a set. The named lists are available as the ``.named_lists`` attribute of the pattern object ::
+          .. sourcecode:: python
         
-                >>> print(p.named_lists)
-                {'options': frozenset({'second', 'fifth', 'fourth', 'third', 'first'})}
+            >>> option_set = ["first", "second", "third", "fourth", "fifth"]
+            >>> p = regex.compile(r"\L<options>", options=option_set)
+        
+          The order of the items is irrelevant, they are treated as a set. The named lists are available as the ``.named_lists`` attribute of the pattern object :
+        
+          .. sourcecode:: python
+        
+            >>> print(p.named_lists)
+            {'options': frozenset({'second', 'fifth', 'fourth', 'third', 'first'})}
         
         * Start and end of word
         
-            ``\m`` matches at the start of a word.
+          ``\m`` matches at the start of a word.
         
-            ``\M`` matches at the end of a word.
+          ``\M`` matches at the end of a word.
         
-            Compare with ``\b``, which matches at the start or end of a word.
+          Compare with ``\b``, which matches at the start or end of a word.
         
         * Unicode line separators
         
-            Normally the only line separator is ``\n`` (``\x0A``), but if the ``WORD`` flag is turned on then the line separators are the pair ``\x0D\x0A``, and ``\x0A``, ``\x0B``, ``\x0C`` and ``\x0D``, plus ``\x85``, ``\u2028`` and ``\u2029`` when working with Unicode.
+          Normally the only line separator is ``\n`` (``\x0A``), but if the ``WORD`` flag is turned on then the line separators are the pair ``\x0D\x0A``, and ``\x0A``, ``\x0B``, ``\x0C`` and ``\x0D``, plus ``\x85``, ``\u2028`` and ``\u2029`` when working with Unicode.
         
-            This affects the regex dot ``"."``, which, with the ``DOTALL`` flag turned off, matches any character except a line separator. It also affects the line anchors ``^`` and ``$`` (in multiline mode).
+          This affects the regex dot ``"."``, which, with the ``DOTALL`` flag turned off, matches any character except a line separator. It also affects the line anchors ``^`` and ``$`` (in multiline mode).
... 13142 lines suppressed ...

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-regex.git



More information about the Python-modules-commits mailing list