sevnpy.io.ReTypeMatch

class sevnpy.io.regexutility.ReTypeMatch[source]

Bases: object

This class is a pure static class used to retrieve the regex matching pattern for various types. At the moment the allowed types are:

  • ‘int’, ‘type’ or int: matching pattern for an integer numer

  • ‘id’: matching pattern for an ID type, i.e. a positive int

  • ‘float’ or float: matching pattern for a float number

  • ‘str’ or ‘name’: generic matching pattern for a string

Examples

ReTypeMatch can be used directly as dictionary providing the type of matching pattern we want to retrieve, e.g.

>>> ReTypeMatch["str"]
   '(?:[0-9|A-Za-z]*\_)?[0-9]*'
>>> ReTypeMatch[float]
'[+|-]?[0-9]+\.?[0-9]*(?i:e)?[+|-]?[0-9]*|(?i:nan)'

It is also possibile to guess the matching patter for a given generic input using the static method guess

>>> ReTypeMatch.guess("hello world")
'(?:[0-9|A-Za-z]*\_)?[0-9]*'
>>> ReTypeMatch.guess("3e10")
'[+|-]?[0-9]+\.?[0-9]*(?i:e)?[+|-]?[0-9]*|(?i:nan)'
>>> ReTypeMatch.guess(13.2)
'[+|-]?[0-9]+\.?[0-9]*(?i:e)?[+|-]?[0-9]*|(?i:nan)'
>>> ReTypeMatch.guess(2)
'[+|-]?[0-9]+\.?[0-9]*(?i:e)?[+|-]?[0-9]*|(?i:nan)'

Methods

__init__

capturing

Get the regex matching patter considering a capturing group

guess

Guess the regex pattern to match in the input value

notcapturing

Get the regex matching patter considering a non-capturing group

__weakref__

list of weak references to the object

classmethod capturing(key: str | Type[int] | Type[float] | Type[str]) str[source]

Get the regex matching patter considering a capturing group

Parameters:

key (str or type int,str,float) – key for which we want to get the matching pattern

Returns:

matching_pattern – return the matching pattern for a capturing group (match_pattern)

Return type:

str

Examples

>>> ReTypeMatch.capturing(float)
>>> '([+|-]?[0-9]+\.?[0-9]*(?i:e)?[+|-]?[0-9]*|(?i:nan))'
classmethod guess(guess_value: int | float | str) str[source]

Guess the regex pattern to match in the input value

Parameters:

guess_value (int|float|str) – Input value for which we want to guess the related pattern matching

Returns:

regex_pattern – The regex pattern matching for the input value

Return type:

str

classmethod notcapturing(key: str | Type[int] | Type[float] | Type[str]) str[source]

Get the regex matching patter considering a non-capturing group

Parameters:

key (str or type int,str,float) – key for which we want to get the matching pattern

Returns:

matchin_pattern – return the matching pattern for a non-capturing group (?:match_pattern)

Return type:

str

Examples

>>> ReTypeMatch.capturing(float)
>>> '(?:[+|-]?[0-9]+\.?[0-9]*(?i:e)?[+|-]?[0-9]*|(?i:nan))'