GroupAtom: A Regex Group#

class my.regex.meta.GroupAtom.GroupAtom(data: str | Self = '', *args: Any, start: str = '', body: str = '', span: Span = <factory>, kind: GroupKind = <GroupKind: 0>, name: str = '', flags: set[str] = {})#

A single group in a regular expression, denoted by parentheses.

Beyond the raw data inherited from Atom, a group knows its start syntax, its kind, its inner body, and – where applicable – its name and inline flags, all of which are parsed automatically at construction time.

Examples

Read the parsed traits of a named, optional group:

>>> group = GroupAtom(r'(?P<year>\d{4})?')
>>> group.kind, group.name, group.body
(GroupKind.NAMED, 'year', '\\d{4}')
>>> str(group.quantifier)
'?'

Inline flags are extracted from the opening syntax:

>>> flagged = GroupAtom(r'(?i:abc)')
>>> flagged.flags, str(flagged.inline_flags)
({'i'}, '(?i)')

I Helper Methods#

GroupAtom.read_data() → None#

Read the raw data field in order to populate start, body, and kind.

GroupAtom.infer_name() → None#

Infer the name of the group if it is a named capture, invocation, or substitution.

GroupAtom.infer_flags() → None#

Infer the flags of the group if it is a flag group.

II Public Methods#

property GroupAtom.is_simple: bool#

Whether this group is a plain/atomic group w/ a simple quantifier.

property GroupAtom.inline_flags: Atom#

An Atom representing the inline flags of this group.