maha.rexy.templates.expression#

Module Contents#

Classes#

Expression

Regex pattern holder.

class Expression(pattern, pickle=False)[source]#

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[source]#

Regular expersion(s) to match

compile(self)[source]#

Compile the regular expersion.

classmethod from_cache(cls, cache)[source]#

Load an expression from cache.

Parameters

cache (str) – Name of the cache file.

Returns

Expression.

Return type

Expression

search(self, text)[source]#

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)[source]#

Match the pattern in the input text.

Parameters

text (str) – Text to match in.

Returns

Matched object.

Return type

Match[str]

fullmatch(self, text)[source]#

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)[source]#

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)[source]#

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]