GroupKind: Enumeration of Regex Group Types#

class my.regex.meta.GroupKind.GroupKind(*values)#

A flag representing one or more “kinds” of regex groups (capturing, lookahead, etc.).

The flags with underscores at the start of their names are unions of the main kinds, exported for caller convenience when filtering by multiple flag types at once.

Examples

Test membership against a union flag:

>>> GroupKind.PLAIN in GroupKind._SIMPLE
True
POSIT = 1#

Positional capturing group – r'(...)'.

PLAIN = 2#

Positional non-capturing group – r'(?:...)'.

FLAGS = 4#

Custom flag group for setting regex flags – r'(?msi)'.

ATOMS = 8#

Atomic group – r'(?>...)'.

RESET = 16#

Branch reset group – r'(?|...)'.

NAMED = 32#

Named capturing group – r'(?P<name>...)'.

INVOC = 64#

Reuse capturing group – r'(?P&name)'/r'(?P>name)'.

SUBST = 128#

Backreference to a capturing group – r'(?P=name)'.

AHEAD = 256#

Positive lookahead assertion – r'(?=...)'.

BEHIND = 512#

Positive lookbehind assertion – r'(?<=...)'.

NOT_AHEAD = 1024#

Negative lookahead assertion – r'(?!...)'.

NOT_BEHIND = 2048#

Negative lookbehind assertion – r'(?<!...)'.

DEFINE = 4096#

Group for defining subpatterns without capturing – r'(?(DEFINE)...)'.

CONDN = 8192#

Named conditional – (?(1)...|...).

CONDL = 16384#

Lookaround conditional – (?(?=...)...|...).

classmethod read(value: str | int | list | MyEnum) → GroupKind#

Parse a value into a GroupKind, additionally recognizing regex group prefixes.

Beyond the member names, integers, and lists handled by MyEnum.read, strings that are not member names are interpreted as group prefixes: '(' alone denotes a positional capturing group, while '(?'-prefixed strings are matched against the known prefix patterns (e.g. '(?:' -> PLAIN, '(?=' -> AHEAD).

Parameters:

value – Member name, group prefix string, integer flag value, list of values, or existing enum member. Falsy input yields the empty flag.

Returns:

Corresponding GroupKind flag.

Raises:

ValueError – If a string is neither a member name nor a recognized group prefix.

Examples

Read group-opening syntax or plain member names:

>>> GroupKind.read('(?:')
GroupKind.PLAIN
>>> GroupKind.read('(')
GroupKind.POSIT
>>> GroupKind.read('(?P<name>')
GroupKind.NAMED
>>> GroupKind.read('named') == GroupKind.NAMED
True