Regexp#

class onetl.file.filter.regexp.Regexp(pattern: str)#

Filter files or directories with path matching a regular expression.

Parameters:
patternre.Pattern

Regular expression (e.g. \d+\.csv) for which any file (only file) path should match.

If input is a string, regular expression will be compiles using re.IGNORECASE and re.DOTALL flags.

Examples

Create regexp filter from string:

from onetl.file.filter import Regexp

regexp = Regexp(r"\d+\.csv")

Create regexp filter from re.Pattern:

import re

from onetl.file.filter import Regexp

regexp = Regexp(re.compile(r"\d+\.csv", re.IGNORECASE | re.DOTALL))
match(path: PathProtocol) bool#

Returns True if path is matching the filter, False otherwise

Examples

from onetl.impl import LocalPath

assert filter.match(LocalPath("/path/to/file.csv"))
assert not filter.match(LocalPath("/path/to/excluded.csv"))
assert filter.match(LocalPath("/path/to/file.csv"))