Match#

class Match(group, match_str, start, end)#

Bases: object

Match extract from a filename.

Parameters:
can_parse()#

Return if the match can be parsed.

Return type:

bool

classmethod from_match(group, match, idx)#

Return Match object from a re.Match object.

Parameters:
  • group (Group) – Group used to get this match.

  • match (Match) – Match object for the complete filename.

  • idx (int) – Index of the group in the match object.

Return type:

Match

get_match(parse=True, raise_on_unparsed=True)#

Get match string or value.

Parameters:
  • parse (bool) – If True (default) return the parsed value instead of the matched string.

  • raise_on_unparsed (bool) – If True (default), will raise an error if the parsed value was asked but the parsing failed. If False, return the string match instead.

Raises:

ValueError – Could not parse the match.

Return type:

Any

end: int#

End index of match in the filename.

group: Group#

Group used to get this match.

property match_parsed: Any | Sentinel#

Return value or Sentinel value if failing to parse.

Returns PARSE_FAIL if an exception is thrown when trying to parse the match.

match_str: str#

String matched in the filename.

start: int#

Start index of match in the filename.