Skip to content

API Documentation

Stephen Zhao edited this page Jan 25, 2022 · 2 revisions

Versioning

Currently the documentation is up-to-date for version 0.2.0 of datetime-matcher.

Contents

class DatetimeMatcher

method search

def search(self, search_dfregex: str, text: str) -> Optional[Match[str]]

Scan through string looking for a match to the pattern, returning a Match object, or None if no match was found.

Uses strftime codes within the dfregex search pattern to match against datetimes.

method match

def match(self, search_dfregex: str, text: str) -> Optional[Match[str]]

Try to apply the pattern at the start of the string, returning a Match object, or None if no match was found.

Uses strftime codes within the dfregex search pattern to match against datetimes.

method findall

def findall(self, search_dfregex: str, text: str) -> List[Match[str]]

Return a list of all non-overlapping matches in the string.

Uses strftime codes within the dfregex search pattern to match against datetimes.

If one or more capturing groups are present in the pattern, return a list of groups; this will be a list of tuples if the pattern has more than one group.

Empty matches are included in the result.

method finditer

def finditer(self, search_dfregex: str, text: str) -> Iterator[Match[str]]

Return an iterator over all non-overlapping matches in the string. For each match, the iterator returns a Match object.

Uses strftime codes within the dfregex search pattern to match against datetimes.

Empty matches are included in the result.

method sub

def sub(self, search_dfregex: str, replacement: str, text: str, count: int = 0) -> str

Return the string obtained by replacing the leftmost non-overlapping occurrences of the pattern in string by the replacement repl. Backslash escapes in replacement are processed.

Uses strftime codes within a dfregex search pattern to extract and substitute datetimes.

If no matches are found, the original text is returned.

Use a non-zero count to limit the number of substitutions.

method extract_datetimes

def extract_datetimes(self, dfregex: str, text: str, count: int = 0) -> Iterator[datetime]

Extracts the leftmost datetimes from text given a dfregex search string.

Uses strftime codes within a dfregex search pattern to extract datetimes.

Returns an Iterator over datetime objects.

Use a non-zero count to limit the number of extractions.

method extract_datetime

def extract_datetime(self, dfregex: str, text: str) -> Optional[datetime]

Extracts the leftmost datetime from text given a dfregex search string.

Uses strftime codes within a dfregex search pattern to extract the datetime.

Returns the matching datetime object if found, otherwise returns None.

method get_regex_from_dfregex

def get_regex_from_dfregex(self, dfregex: str, is_capture_dfs: bool = False) -> str

Converts a dfregex search pattern to its corresponding conventional regex search pattern.

By default, the datetime format groups are not captured.