mafw.tools.regexp

Module implements some basic functions involving regular expressions.

Functions

extract_protocol(url)

Extract the protocol portion from a database connection URL.

normalize_sql_spaces(sql_string)

Normalize multiple consecutive spaces in SQL string to single spaces.

mafw.tools.regexp.extract_protocol(url: str) str | None[source]

Extract the protocol portion from a database connection URL.

The extract_protocol function takes a database connection URL string as input and extracts the protocol portion (the part before “://”). This function is useful for identifying the database type from connection strings.

Parameters:

url (str) – The url from which the protocol will be extracted.

Returns:

The protocol or None, if the extraction failed

Return type:

str | None

mafw.tools.regexp.normalize_sql_spaces(sql_string: str) str[source]

Normalize multiple consecutive spaces in SQL string to single spaces. Only handles spaces, preserves other whitespace characters.

Parameters:

sql_string (str) – The SQL string for space normalization.

Returns:

The normalized SQL command.

Return type:

str