regex
Tu je trieda RegEx, ktorá obalí regulárny výraz a dáta, na ktorých má byť vykonaný.
Tiež je tu funkcia create_regex(), ktorá vytvorí z jej argumentov inštanciu
RegEx pre výraz, ktorý je daný jej argumentami.
from susi_lib import RegEx, create_regex, Selection
# takto sa importujú všetky funkcie odtiaľto
Provides RegEx class for better work with regular expressions,
create_regex() function to create a RegEx instance based
without the full knowledge of regular expression syntax.
- class susi_lib.regex.RegEx(pattern: str, data: list[str] | str | None = None)[source]
Class to store and execute a regular expression on some provided data.
Create
RegExinstance.- Raises:
TypeErrorwhen invalid parameter types are passed- Raises:
ValueErrorwhen a parameter has invalid value- Parameters:
- execute() list[str][source]
Executes the regular expression on provided data. Need to provide data first.
- Raises:
AttributeErrorwhenset_data()wasn’t called with valid data before calling this method- Returns:
List of all found matches
- Return type:
- class susi_lib.regex.Selection(value, names=<not given>, *values, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Enum to specify what to do with a set of characters when creating RE by create_regex.
- ANY = 3
Override this set to match any character
- INVERT = 2
Invert the set
- NONE = 1
Don’t do anything
- susi_lib.regex.create_regex(*args: tuple[str, Selection], data: list[str] | str | None = None, length: int | tuple[int, int] | None = None, letters: str | None = None, invert: bool = False) RegEx[source]
Creates a RegEx object from arguments.
If
argsis specified, it will loop through it and create a pattern. Each tuple contains a set of character and enum to specify what to do with it. Sets of characters are by default wanted. The length of the wanted words will be the numbers of tuples provided.If
argsis not specified, it will use remaining keyword arguments to create aRegExobject. Length determines length of the words, letters a set of wanted letters and invert wether to turn wanted letters into unwanted.- Raises:
TypeErrorwhen invalid parameter types are passed- Raises:
ValueErrorwhen a parameter has invalid value- Parameters:
args (tuple[str, Selection]) – Set of wanted characters and enum to specify special action.
length (int | tuple[int, int] | None) – Int specifying length of the word or a pair (begin, end) specifying a range
letters (str | None) – Set of wanted letters
invert (bool) – Bool value, set to
Trueto turn wanted letters to unwanted
- Returns:
RegExobject with desired pattern- Return type: