Regexp¶
Bases: BaseFileFilter, FrozenModel
"Filter files or directories with path matching a regular expression.
.. versionadded:: 0.8.0
Replaces deprecated onetl.core.FileFilter
Parameters:
-
pattern(:obj:re.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.IGNORECASEandre.DOTALLflags.
Examples:
Create regexp filter from string:
.. code:: python
from onetl.file.filter import Regexp
regexp = Regexp(r"\d+\.csv")
Create regexp filter from :obj:re.Pattern:
.. code:: python
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
.. versionadded:: 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