For testing and comparison with the current 're' module the new implementation is in the form of a module called 'regex'.


Flags
=====

There are 2 kinds of flag: scoped and global. Scoped flags can apply to only part of a pattern and can be turned on or off; global flags apply to the entire pattern and can only be turned on.

The scoped flags are: IGNORECASE, MULTILINE, DOTALL, VERBOSE.

The global flags are: ASCII, LOCALE, UNICODE, ZEROWIDTH.


Character classes
=================

The character classes \w, \W, \s, \S, and also \b and \B, are affected by the ASCII, LOCALE and UNICODE flags. In the current 're' module, if you don't turn on the UNICODE flag then a pattern will assume that the string you're trying to match is ASCII, even if it's a Unicode string.

In this implementation, however, if you don't specify whether the pattern is for ASCII or Unicode then it'll decide depending on whether the string you're matching is a bytestring or a Unicode string.

To be exact:

    if unicode_flag or string_is_unicode and not ascii_flag:
        unicode_classes
    elif locale_flag:
        locale_classes
    else:
        ascii_classes


Additional features
===================

Atomic grouping (issue #433030)
    (?>...)
    If the following pattern subsequently fails, then the subpattern as a whole will fail.

Possessive quantifiers.
    (?:...)?+
    (?:...)*+
    (?:...)++
    (?:...){min,max}+
    The subpattern is matched up to 'max' times. If the following pattern subsequently fails, then all of the repeated subpatterns will fail as a whole. For example, "(?:...)++" is equivalent to "(?>(?:...)+)".

Scoped flags (issue #433028)
    (?flags-flags:...)
    The flags will apply only to the subpattern. Flags can be turned on or off.

Inline flags (#433024, #433027)
    (?flags-flags)
    The flags will apply to the end of the group or pattern. Flags can be turned on or off.

Repeated repeats (#2537)
    A regex like r'((x|y+)*)*' will be accepted and will work correctly, but should now complete in a reasonable time.

Definition of 'word' character (#1693050)
    The definition of a 'word' character has been expanded for Unicode. This applies to \w, \W, \b and \B.

Groups in lookahead and lookbehind (#814253)
    Groups and group references are permitted in both lookahead and lookbehind.

Variable-length lookbehind
    A lookbehind can now match a variable-length string.

Correct handling of charset with ignore case flag (#3511)
    Ranges within charsets are now handled correctly when the ignore-case flag is turned on.

Unmatched group in replacement (#1519638)
    An unmatched group is now treated as an empty string in a replacement template.

'Pathological' patterns (#1566086, #1662581, #1448325, #1721518, #1297193)
    'Pathological' patterns should now complete in a reasonable time.

Flags argument for re.split, re.sub and re.subn (#3482)
    re.split, re.sub and re.subn now support a 'flags' argument.

Unicode escapes (#3665)
    The Unicode escapes \uxxxx and \Uxxxxxxxx are now supported.

Large patterns (#1160)
    Patterns can now be much larger.

Zero-width match with re.finditer (#1647489)
    re.finditer now behaves correctly when it splits at a zero-width match.

Zero-width split with re.split (#3262)
    re.split can now split at a zero-width match if the zero-width flag is turned on. When the flag is turned off the current behaviour is unchanged because the BDFL thinks that some existing software might depend on it.

Subscripting for groups
    A match object now accepts access to the captured groups via subscripting:

    >>> m = regex.search("(?<before>.*?)(?<num>\d+)(?<after>.*)", "pqr123stu")
    >>> print m["before"]
    pqr
    >>> print m["num"]
    123
    >>> print m["after"]
    stu
    >>> print len(m)
    4
    >>> print m[:]
    ('pqr123stu', 'pqr', '123', 'stu')

Named groups
    Named groups can now be named with (?<name>...) as well as the current (?P<name>...).

Group references
    Groups can be referenced within a pattern with \g<name>. This also allows there to be more than 99 groups.

Named characters
    \N{name}
    Named characters are now supported.

Unicode properties
    \p{name}
    \P{name}
    Unicode properties are now supported. \p{name} matches a character which has property 'name' and \P{name} matches a character which doesn't have property 'name'. Script names are not currently supported.


Possible features
=================

Relative group references.

Template?

Posix classes.

Overlapped findall/finditer?
