Skip to content

Regexp

Bases: BaseFileFilter, FrozenModel

Filter files or directories with path matching a regular expression.

Added in 0.8.0

Replaces deprecated onetl.core.FileFilter

Parameters:

  • pattern (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)

Returns True if path is matching the filter, False otherwise

Added in 0.8.0

Examples:

>>> from onetl.impl import LocalPath
>>> filter.match(LocalPath("/path/to/file.csv"))
True
>>> filter.match(LocalPath("/path/to/excluded.csv"))
False
>>> filter.match(LocalPath("/path/to/file.csv"))
True