maha.rexy#
Subpackages#
Submodules#
Package Contents#
Classes#
Regex pattern holder. |
|
A group of expressions that match the same dimension. Expressions are evaluated |
|
A result of a single expression. |
Functions#
|
Returns an optional non capturing group of patterns. |
|
Returns a non capturing groups of patterns. |
|
Returns a positive lookbehind pattern. |
|
Returns positive lookahead pattern |
|
Returns named pattern group |
|
Returns a capturing group pattern |
- optional_non_capturing_group(*patterns)[source]#
Returns an optional non capturing group of patterns.
- Parameters
patterns (Expression | str) –
- non_capturing_group(*patterns)[source]#
Returns a non capturing groups of patterns.
- Parameters
patterns (Expression | str) –
- positive_lookbehind(*patterns)[source]#
Returns a positive lookbehind pattern.
- Parameters
patterns (Expression | str) –
- positive_lookahead(*patterns)[source]#
Returns positive lookahead pattern
- Parameters
patterns (Expression | str) –
- named_group(name, pattern)[source]#
Returns named pattern group
- Parameters
name (str) –
pattern (Expression | str) –
- capture_group(*patterns)[source]#
Returns a capturing group pattern
- Parameters
patterns (Expression | str) –
- class Expression(pattern, pickle=False)#
Regex pattern holder.
- Parameters
pattern (str) – Regular expression pattern.
pickle (bool) – If
True, the compiled pattern will be pickled. This is useful to save compilation time for large patterns.
- pattern :str#
Regular expersion(s) to match
- compile(self)#
Compile the regular expersion.
- classmethod from_cache(cls, cache)#
Load an expression from cache.
- Parameters
cache (str) – Name of the cache file.
- Returns
Expression.
- Return type
- search(self, text)#
Search for the pattern in the input
text.- Parameters
text (str) – Text to search in.
- Returns
Matched object.
- Return type
regex.Match
- match(self, text)#
Match the pattern in the input
text.- Parameters
text (str) – Text to match in.
- Returns
Matched object.
- Return type
Match[str]
- fullmatch(self, text)#
Match the pattern in the input
text.- Parameters
text (str) – Text to match in.
- Returns
Matched object.
- Return type
Match[str]
- sub(self, repl, text)#
Replace all occurrences of the pattern in the input
text.- Parameters
repl (str) – Replacement string.
text (str) – Text to replace.
- Returns
Text with replaced occurrences.
- Return type
str
- parse(self, text)#
Extract values from the input
text.- Parameters
text (str) – Text to extract the value from.
- Yields
ExpressionResult– Extracted value.- Return type
Iterable[maha.rexy.templates.expression_result.ExpressionResult]
- class ExpressionGroup(*expressions, smart=False)#
A group of expressions that match the same dimension. Expressions are evaluated in the order they were added.
- Parameters
*expressions – List of expressions to match. High-priority expressions should be passed first.
smart (bool, optional) – Whether to parse the text in a smart way. See
smart_parse().expressions (rx.Expression | ExpressionGroup) –
- compile_expressions(self)#
- add(self, *expression)#
Add an expression to the group.
- Parameters
*expression – Expressions to add.
expression (maha.rexy.Expression) –
- Return type
None
- join(self)#
Returns non capturing group of the expressions.
- Returns
Non capturing group of the patterns.
- Return type
str
- get_matched_expression(self, text)#
Returns the expression that fully matches the text.
- Parameters
text (str) – Text to match.
- Returns
Expression that fully matches the text.
- Return type
- parse(self, text)#
Parses the text.
- Parameters
text (str) – Text to parse.
- Yields
ExpressionResult– Extracted value.- Return type
Iterable[maha.rexy.ExpressionResult]
- normal_parse(self, text)#
Parse the input
textand return the extracted values.- Parameters
text (str) – Text to parse.
- Yields
ExpressionResult– Extracted value.- Return type
Iterable[maha.rexy.ExpressionResult]
- smart_parse(self, text)#
Parses the text. If a value matches two or more expressions, only the first expression parses the value, no value is matched more than once. This means high-priority expressions should be added to the group first.
- Parameters
text (str) – Text to parse.
- Yields
ExpressionResult– Extracted value.- Return type
Iterable[maha.rexy.ExpressionResult]