string_evaluations¶
shortfx.fxString.string_evaluations
¶
Functions¶
automated_readability_index(text: str) -> float
¶
Compute the Automated Readability Index (ARI) for English text.
Returns an approximate US grade level needed to understand the text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
English prose text. |
required |
Returns:
| Type | Description |
|---|---|
float
|
ARI score (approximate US grade level). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
ValueError
|
If text has no sentences. |
Usage Example
round(automated_readability_index('The cat sat on the mat.'), 1) -5.1
Complexity: O(n)
Source code in shortfx/fxString/string_evaluations.py
avg_word_length(text: str) -> float
¶
Compute the average word length in text.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Source string. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Average word length. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
ValueError
|
If text has no words. |
Usage Example
avg_word_length('The cat sat') 3.0
Complexity: O(n)
Source code in shortfx/fxString/string_evaluations.py
char_frequency(text: str) -> dict[str, int]
¶
Calculates the frequency of each character in a string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The input string. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, int]
|
A dictionary mapping each character to its count. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
Example
char_frequency("aab")
Complexity: O(n)
Source code in shortfx/fxString/string_evaluations.py
check_password_strength(password: str) -> int
¶
Evaluate password strength on a 0–100 score scale.
Description
The score is computed from: length contribution (up to 40 pts), character diversity — uppercase, lowercase, digits, special characters (up to 40 pts) — and a bonus for entropy above 3.0 bits/char (up to 20 pts). The result is clamped to [0, 100].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
password
|
str
|
The password string to evaluate. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Strength score as an integer in [0, 100]. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If password is not a string. |
Usage Example
check_password_strength("abc") 18 check_password_strength("C0mpl3x!Pass#2026") 100
Complexity: O(n) where n is the password length.
Source code in shortfx/fxString/string_evaluations.py
2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 | |
check_substring_at_position(main_string: str, substring: str, position: int | str) -> bool
¶
Checks if a substring exists at a specified position within a main string.
This function supports checking at a numerical index, or at the 'start' or 'end' of the main string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
main_string
|
str
|
The string to search within. |
required |
substring
|
str
|
The substring to search for. |
required |
position
|
int | str
|
The starting index for the search, or 'start'/'end'. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the substring is found at the specified position, False otherwise. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If 'position' is an integer and is out of the valid range for 'main_string'. |
TypeError
|
If 'position' is not an int or a string ('start' or 'end'). |
Example of use
check_substring_at_position("hello world", "hello", "start") True check_substring_at_position("hello world", "world", "end") True check_substring_at_position("hello world", "lo", 3) True check_substring_at_position("hello world", "lo", 2) False check_substring_at_position("hello world", "xyz", "start") False
Source code in shortfx/fxString/string_evaluations.py
coleman_liau_index(text: str) -> float
¶
Compute the Coleman–Liau readability index for English text.
Returns an approximate US grade level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
English prose text. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Coleman–Liau index. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
ValueError
|
If text has no words. |
Usage Example
round(coleman_liau_index('The cat sat on the mat.'), 1) -4.1
Complexity: O(n)
Source code in shortfx/fxString/string_evaluations.py
compare_strings(string1: str, string2: str, case_sensitive: bool = True) -> int
¶
Compare two strings lexicographically.
Returns -1, 0, or 1 depending on whether string1 is less
than, equal to, or greater than string2. Equivalent to VBA StrComp.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
string1
|
str
|
First string. |
required |
string2
|
str
|
Second string. |
required |
case_sensitive
|
bool
|
If |
True
|
Returns:
| Type | Description |
|---|---|
int
|
|
Example
compare_strings("apple", "banana") -1 compare_strings("ABC", "abc", case_sensitive=False) 0
Complexity: O(min(len(string1), len(string2)))
Source code in shortfx/fxString/string_evaluations.py
count_sentences(text: str) -> int
¶
Count the number of sentences in a text.
A sentence is defined as text ending with ., !, or ?.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Input text. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Number of sentences. |
Example
count_sentences("Hello world. How are you? Fine!") 3
Complexity: O(n)
Source code in shortfx/fxString/string_evaluations.py
detect_quotes(text: Optional[str]) -> bool
¶
Detects if a string is enclosed in either single or double quotes.
This function checks whether the input string starts and ends with the same quote character (either single quote ' or double quote "). It performs input validation to handle edge cases gracefully.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
Optional[str]
|
The string to analyze. Can be None. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the string is quoted with matching single or double quotes, False otherwise (including None input, non-string input, or strings that are too short to be quoted). |
Example of use
detect_quotes("'hello world'") True detect_quotes('"Python is great"') True detect_quotes("unquoted text") False detect_quotes("'mismatched"") False detect_quotes("") False detect_quotes(None) False detect_quotes("'") False
Cost
O(1) - Constant time operation regardless of string length.
Source code in shortfx/fxString/string_evaluations.py
domain_from_email(email_address: str) -> str | None
¶
Extracts the domain part from a given email address string.
This function utilizes a helper function (parse_email) to safely parse the email address. If the email is valid and contains a domain, that domain is returned. Otherwise, None is returned, indicating an invalid or unparsable email address.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
email_address
|
str
|
The full email address string from which to extract the domain. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: The domain string (e.g., 'example.com') if the email is valid, otherwise None. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the input email_address is not a string. |
Example of use
domain_from_email("user@example.com") 'example.com' domain_from_email("another.user@sub.domain.co.uk") 'sub.domain.co.uk' domain_from_email("invalid-email-format") None domain_from_email("noat.com") None domain_from_email(123) Traceback (most recent call last): ... TypeError: Input must be a string.
Source code in shortfx/fxString/string_evaluations.py
ends_with_substring(input_string: str, suffix: str, case_sensitive: bool = True) -> bool
¶
Checks if a string ends with a specific substring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_string
|
str
|
The string to check. |
required |
suffix
|
str
|
The substring to look for at the end. |
required |
case_sensitive
|
bool
|
If True, the comparison is case-sensitive. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the string ends with the suffix, False otherwise. |
Source code in shortfx/fxString/string_evaluations.py
flesch_reading_ease(text: str) -> float
¶
Estimate the Flesch Reading Ease score for English text.
Score ranges typically 0-100 (higher = easier to read). Uses a simple heuristic syllable counter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
English prose text. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Flesch Reading Ease score. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
ValueError
|
If text has no words. |
Usage Example
round(flesch_reading_ease('The cat sat on the mat.'), 1) 116.1
Complexity: O(n)
Source code in shortfx/fxString/string_evaluations.py
get_phones(phone, p_separator='')
¶
Extracts potential phone numbers from a string.
A phone number is identified as a sequence of digits that: 1. Is at least 5 digits long after removing common phone number delimiters (spaces, hyphens, parentheses, dots) and any custom separators provided. 2. May optionally start with a '+' sign. 3. May contain common phone number delimiters internally.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phone
|
str
|
The input string to parse for phone numbers. |
required |
p_separator
|
str
|
A string containing additional characters that should be treated as allowed delimiters within a phone number but removed in the final output. Defaults to an empty string. |
''
|
Returns:
| Type | Description |
|---|---|
|
list[str] or None: A list of cleaned phone numbers (digits only) if found, otherwise None. |
Source code in shortfx/fxString/string_evaluations.py
get_postalcode(address: str) -> list[str] | None
¶
Extracts 5-digit or 4-digit postal codes from an address string.
It first attempts to find all 5-digit number sequences that are whole "words". If no 5-digit codes are found, it then attempts to find all 4-digit number sequences that are whole "words".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
address
|
str
|
The input address string. |
required |
Returns:
| Type | Description |
|---|---|
list[str] | None
|
list[str] or None: A list of found postal codes (as strings).
Returns an empty list if no codes are found.
Returns None if the input |
Source code in shortfx/fxString/string_evaluations.py
gunning_fog_index(text: str) -> float
¶
Estimate the Gunning Fog readability index for English text.
Higher values indicate harder text. A score of ~7–8 is considered easy reading; 12+ is considered hard.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
English prose text. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Gunning Fog index. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
ValueError
|
If text has no sentences. |
Usage Example
round(gunning_fog_index('The cat sat on the mat.'), 1) 2.4
Complexity: O(n)
Source code in shortfx/fxString/string_evaluations.py
has_date_format(value: str) -> bool
¶
Verifies if a given string matches any of a predefined list of common date and datetime formats.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
The string to be checked. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the string matches one of the formats, False otherwise. |
Source code in shortfx/fxString/string_evaluations.py
has_numbers(input_string: str) -> bool
¶
Checks if the input string contains any numeric digits (0-9).
Delegates to :func:~shortfx.fxString.string_validations.contains_digit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_string
|
str
|
The string to check for digits. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the string contains at least one digit, False otherwise. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the input is not a string. |
Example
has_numbers("abc123def") True has_numbers("python") False
Source code in shortfx/fxString/string_evaluations.py
has_substring(input_string: str, char_to_find: str) -> bool
¶
Checks if a specific character is present within a given string.
This function utilizes the 'in' operator, which is the most Pythonic and readable way to determine if a substring (in this case, a single character) exists within another string. It returns True if the character is found, and False otherwise.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_string
|
str
|
The string to search within. |
required |
char_to_find
|
str
|
The character (or single-character string) to search for. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if 'char_to_find' is found in 'input_string', False otherwise. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If 'char_to_find' is not a single character. |
Example
has_substring("hello world", "o") returns True has_substring("python", "z") returns False has_substring("programming", "g") returns True
Source code in shortfx/fxString/string_evaluations.py
is_alphabetic(alpha_string)
¶
Checks if a given input is a single alphabetic character (letter), including common accented characters.
Source code in shortfx/fxString/string_evaluations.py
is_anagram(a: str, b: str) -> bool
¶
Checks whether two strings are anagrams of each other.
Comparison is case-insensitive and ignores spaces and punctuation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
str
|
First string. |
required |
b
|
str
|
Second string. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if both strings contain exactly the same letters. |
Example
is_anagram("listen", "silent") True is_anagram("hello", "world") False
Complexity: O(n log n)
Source code in shortfx/fxString/string_evaluations.py
is_balanced_brackets(text: str) -> bool
¶
Check whether all brackets in text are properly balanced and nested.
Validates (), [], and {}.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Input string. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
in the correct order. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
Example
is_balanced_brackets("({[]})") True is_balanced_brackets("([)]") False
Complexity: O(n)
Source code in shortfx/fxString/string_evaluations.py
is_credit_card_format(text: str) -> bool
¶
Validate a credit card number using the Luhn algorithm.
Strips spaces and dashes before validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Credit card number string. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the number passes the Luhn check. |
Example
is_credit_card_format('4532015112830366') True is_credit_card_format('1234567890123456') False
Complexity: O(n)
Source code in shortfx/fxString/string_evaluations.py
is_email_format(email_string: str) -> bool
¶
Checks if a given string has the general format of an email address.
This function validates a string against a common regular expression pattern for email addresses. It verifies the presence of a local part, an '@' symbol, and a domain part (which follows standard domain naming conventions). It does not validate the email against a list of known domains or check for its existence.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
email_string
|
str
|
The string to be checked for email format validity. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the string adheres to the general email format, False otherwise. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the input is not a string. |
Example of use
is_email_format("user@example.com") True is_email_format("first.last@sub.domain.org") True is_email_format("user+tag@domain.co.uk") True is_email_format("invalid-email") False is_email_format("user@domain") # Missing TLD False is_email_format("user@.com") # Invalid domain start False
Source code in shortfx/fxString/string_evaluations.py
is_heterogram(text: str) -> bool
¶
Check if text has no repeated characters at all (including spaces).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Source string. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if heterogram. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
Usage Example
is_heterogram('abcde') True
Complexity: O(n)
Source code in shortfx/fxString/string_evaluations.py
is_internet_domain_format(domain_string: str) -> bool
¶
Checks if a given string adheres to the general format of an internet domain name.
This function validates a string against common internet domain naming conventions. It ensures the string adheres to the standard format for domain names, including alphanumeric characters, hyphens (not at the beginning or end), and a valid-looking top-level domain (TLD). It does not validate against a specific list of registered TLDs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domain_string
|
str
|
The string to be checked for domain format validity. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the string adheres to the general internet domain format, False otherwise. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the input is not a string. |
Example of use
is_internet_domain_format("example.com") True is_internet_domain_format("sub.domain.org") True is_internet_domain_format("invalid-domain") False is_internet_domain_format("domain.c") # Fails because TLD is too short False
Source code in shortfx/fxString/string_evaluations.py
is_ipv4(text: str) -> bool
¶
Check whether a string is a valid IPv4 address.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
String to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the string is a valid IPv4 address. |
Example
is_ipv4('192.168.1.1') True is_ipv4('999.999.999.999') False
Complexity: O(1)
Source code in shortfx/fxString/string_evaluations.py
is_ipv6(text: str) -> bool
¶
Check whether a string is a valid IPv6 address.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
String to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the string is a valid IPv6 address. |
Example
is_ipv6('::1') True is_ipv6('192.168.1.1') False
Complexity: O(1)
Source code in shortfx/fxString/string_evaluations.py
is_isogram(text: str) -> bool
¶
Check if text is an isogram (no repeating letters, case-insensitive).
Non-alphabetic characters are ignored.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Source string. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if isogram. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
Usage Example
is_isogram('subdermatoglyphic') True
Complexity: O(n)
Source code in shortfx/fxString/string_evaluations.py
is_json(text: str) -> bool
¶
Check whether a string is valid JSON.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
String to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the string can be parsed as JSON. |
Example
is_json('{"key": "value"}') True is_json('not json') False
Complexity: O(n)
Source code in shortfx/fxString/string_evaluations.py
is_lipogram(text: str, letter: str) -> bool
¶
Check if text avoids letter entirely (case-insensitive).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Source string. |
required |
letter
|
str
|
Single letter to check absence of. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if letter is absent. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If arguments are not strings. |
ValueError
|
If letter is not a single alphabetic character. |
Usage Example
is_lipogram('The quick brown fox jumps over the lazy dog', 'z') False
Complexity: O(n)
Source code in shortfx/fxString/string_evaluations.py
is_numeric(input_string: str) -> bool
¶
Checks if a given string represents a numeric value (integer or float).
This function attempts to cast the input string to a float. If the conversion is successful, it means the string can be interpreted as a number. This approach handles both integers and floating-point numbers, including negative values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_string
|
str
|
The string to check. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the string is numeric, False otherwise. |
Example
is_numeric("123") returns True is_numeric("-45.67") returns True is_numeric("abc") returns False is_numeric("12a") returns False
Source code in shortfx/fxString/string_evaluations.py
is_palindrome(text: str) -> bool
¶
Checks whether a text is a palindrome (ignoring case, spaces and punctuation).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The input string to evaluate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the cleaned text reads the same forwards and backwards. |
Example
is_palindrome("A man a plan a canal Panama") True is_palindrome("hello") False
Complexity: O(n)
Source code in shortfx/fxString/string_evaluations.py
is_pangram(text: str, alphabet: str = 'abcdefghijklmnopqrstuvwxyz') -> bool
¶
Checks whether a text contains every letter of the given alphabet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The input string. |
required |
alphabet
|
str
|
The set of required letters (default: English a-z). |
'abcdefghijklmnopqrstuvwxyz'
|
Returns:
| Type | Description |
|---|---|
bool
|
True if all alphabet letters appear at least once in text. |
Example
is_pangram("The quick brown fox jumps over the lazy dog") True is_pangram("Hello world") False
Complexity: O(n + a) where a is the alphabet length.
Source code in shortfx/fxString/string_evaluations.py
is_tautogram(text: str) -> bool
¶
Check if every word in text starts with the same letter (case-insensitive).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Source string (whitespace-delimited words). |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if tautogram. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
Usage Example
is_tautogram('Peter Piper picked peppers') True
Complexity: O(n)
Source code in shortfx/fxString/string_evaluations.py
is_url_format(url_string: str) -> bool
¶
Checks if a given string has the general format of a URL.
This function validates a string against a common regular expression pattern for URLs. It considers various components such as scheme (http, https, ftp, etc.), domain/IP address, optional port, path, query parameters, and fragment identifier. It does not check if the URL actually exists or is accessible, only its structural validity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
url_string
|
str
|
The string to be checked for URL format validity. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the string adheres to the general URL format, False otherwise. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the input is not a string. |
Example of use
is_url_format("https://www.example.com") True is_url_format("http://localhost:8080/path/to/resource?id=123#section") True is_url_format("ftp://files.server.org/data.zip") True is_url_format("invalid-url") False is_url_format("www.example.com") # No scheme False is_url_format("example.com/path") # No scheme False
Source code in shortfx/fxString/string_evaluations.py
is_uuid(text: str) -> bool
¶
Check whether a string matches the UUID format (any version).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
String to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the string is a valid UUID. |
Example
is_uuid('550e8400-e29b-41d4-a716-446655440000') True is_uuid('not-a-uuid') False
Complexity: O(1)
Source code in shortfx/fxString/string_evaluations.py
is_valid_base64(text: str) -> bool
¶
Check whether a string is valid Base64 encoding.
Validates the character set (A-Za-z0-9+/=) and correct padding.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
String to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
Example
is_valid_base64("SGVsbG8gV29ybGQ=") True
Complexity: O(n)
Source code in shortfx/fxString/string_evaluations.py
is_valid_cron(expr: str) -> bool
¶
Validate a 5-field cron expression.
Checks that each of the five space-separated fields (minute, hour, day-of-month, month, day-of-week) contains only valid characters and ranges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
expr
|
str
|
Cron expression string. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If expr is not a string. |
Example
is_valid_cron("0 12 * * 1-5") True is_valid_cron("60 25 * * *") False
Complexity: O(n)
Source code in shortfx/fxString/string_evaluations.py
1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 | |
is_valid_cusip(text: str) -> bool
¶
Validate a CUSIP (Committee on Uniform Securities Identification Procedures) code.
Description
A CUSIP is 9 characters: 6 alphanumeric (issuer) + 2 alphanumeric (issue) + 1 check digit. The check digit is computed via a weighted Luhn-like algorithm where odd-position digits are multiplied by 1 and even-position digits by 2 (after letter-to- number conversion).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The CUSIP code to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the CUSIP is valid. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
Usage Example
is_valid_cusip("037833100") True is_valid_cusip("037833101") False
Complexity: O(1)
Source code in shortfx/fxString/string_evaluations.py
2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 | |
is_valid_domain_format(domain_string: str) -> bool
¶
Checks if a string conforms to a common internet domain name format.
Delegates to :func:is_internet_domain_format after handling None
inputs (returns None for None).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
domain_string
|
str
|
The string to be validated as a domain name. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the string matches the expected domain format, False otherwise. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the input 'domain_string' is not a string. |
Example of use
is_valid_domain_format("example.com") True is_valid_domain_format("invalid") False
Source code in shortfx/fxString/string_evaluations.py
is_valid_e164_phone(text: str) -> bool
¶
Validate an E.164 international phone number.
Description
E.164 format: + followed by 1 to 15 digits, no spaces or
dashes. This is the ITU-T standard used in SIP, SMS, and
international dialling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The phone number string to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the string matches E.164 format. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
Usage Example
is_valid_e164_phone("+34612345678") True is_valid_e164_phone("612345678") False is_valid_e164_phone("+1234567890123456") False
Complexity: O(1)
Source code in shortfx/fxString/string_evaluations.py
is_valid_ean(text: str) -> bool
¶
Validates an EAN-8 or EAN-13 barcode number.
Description
Checks the length (8 or 13 digits) and the weighted-sum check digit used in European Article Numbers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The EAN string to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the EAN is valid. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
Usage Example
is_valid_ean("4006381333931") True is_valid_ean("96385074") True
Complexity: O(n)
Source code in shortfx/fxString/string_evaluations.py
is_valid_email_format(email_string: str) -> bool
¶
Checks if a string has a valid email format.
Delegates to :func:is_email_format, which uses an RFC 5322-aligned
regular expression for validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
email_string
|
str
|
The string to be validated as an email address. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the string is a valid email format, False otherwise. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If the input 'email_string' is not a string. |
Example of use
is_valid_email_format("test@example.com") True is_valid_email_format("invalid-email") False
Source code in shortfx/fxString/string_evaluations.py
is_valid_hex_color(text: str) -> bool
¶
Check whether text is a valid hex colour code.
Accepts #RGB, #RGBA, #RRGGBB, or #RRGGBBAA.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Input string. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
Example
is_valid_hex_color("#FF8800") True is_valid_hex_color("red") False
Complexity: O(1)
Source code in shortfx/fxString/string_evaluations.py
is_valid_iban(text: str) -> bool
¶
Validates an International Bank Account Number (IBAN).
Description
Checks both the structural format (2 letter country code, 2 check digits, and up to 30 alphanumeric BBAN characters) and the MOD-97 check-digit integrity defined by ISO 13616.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The IBAN string to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the IBAN is structurally valid and passes MOD-97 check. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
Usage Example
is_valid_iban("GB29 NWBK 6016 1331 9268 19") True is_valid_iban("GB29 NWBK 6016 1331 9268 18") False
Complexity: O(n)
Source code in shortfx/fxString/string_evaluations.py
is_valid_ipv4(text: str) -> bool
¶
Validate an IPv4 address string.
Checks four dot-separated decimal octets, each in [0, 255].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
String to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
Example
is_valid_ipv4("192.168.1.1") True
Complexity: O(1)
Source code in shortfx/fxString/string_evaluations.py
is_valid_ipv6(text: str) -> bool
¶
Validate an IPv6 address string.
Supports full and compressed (::\ ) notation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
String to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
Example
is_valid_ipv6("2001:0db8:85a3::8a2e:0370:7334") True
Complexity: O(1)
Source code in shortfx/fxString/string_evaluations.py
is_valid_isbn(text: str) -> bool
¶
Validates an ISBN-10 or ISBN-13 string.
Description
Strips hyphens/spaces and validates the check digit using the appropriate algorithm (modular arithmetic for ISBN-10 and weighted sum modulo 10 for ISBN-13).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The ISBN string to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the ISBN is valid. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
Usage Example
is_valid_isbn("978-3-16-148410-0") True is_valid_isbn("0-306-40615-2") True
Complexity: O(n)
Source code in shortfx/fxString/string_evaluations.py
is_valid_isin(text: str) -> bool
¶
Validate an ISIN (International Securities Identification Number).
Description
An ISIN consists of a 2-letter country code, a 9-character alphanumeric national identifier, and a single check digit. Validation converts letters to numbers (A=10..Z=35), concatenates the digit string, and applies the Luhn algorithm.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The ISIN string to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the ISIN is valid. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
Usage Example
is_valid_isin("US0378331005") True is_valid_isin("US0378331006") False
Complexity: O(n)
Source code in shortfx/fxString/string_evaluations.py
2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 | |
is_valid_issn(text: str) -> bool
¶
Validate an ISSN (International Standard Serial Number).
Description
An ISSN is 8 digits (with optional hyphen after digit 4). The check digit (last char, may be 'X' for 10) is validated using a weighted mod-11 algorithm with weights 8..2.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The ISSN to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the ISSN is valid. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
Usage Example
is_valid_issn("0378-5955") True is_valid_issn("0000-0019") True
Complexity: O(1)
Source code in shortfx/fxString/string_evaluations.py
is_valid_luhn(text: str) -> bool
¶
Validates a numeric string using the Luhn (mod-10) algorithm.
Description
Implements the standard Luhn algorithm used for credit card numbers, IMEI codes, and other identifiers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The numeric string to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the string passes the Luhn check. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
Usage Example
is_valid_luhn("4539148803436467") True is_valid_luhn("1234567890") False
Complexity: O(n)
Source code in shortfx/fxString/string_evaluations.py
is_valid_mac_address(text: str) -> bool
¶
Validate a MAC address string.
Accepts colon, dash, and dot notations:
AA:BB:CC:DD:EE:FF, AA-BB-CC-DD-EE-FF, AABB.CCDD.EEFF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
String to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
Example
is_valid_mac_address("00:1A:2B:3C:4D:5E") True
Complexity: O(1)
Source code in shortfx/fxString/string_evaluations.py
is_valid_mime_type(text: str) -> bool
¶
Validates whether a string matches the MIME type format.
Checks for the standard type/subtype structure (e.g.
text/html, application/json).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The string to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
Example
is_valid_mime_type("application/json") True is_valid_mime_type("not-a-mime") False
Complexity: O(n)
Source code in shortfx/fxString/string_evaluations.py
is_valid_regex(pattern: str) -> bool
¶
Checks whether a string is a syntactically valid regular expression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pattern
|
str
|
The regex pattern string to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If pattern is not a string. |
Example
is_valid_regex(r"\d{3}-\d{4}") True is_valid_regex("[unclosed") False
Complexity: O(n)
Source code in shortfx/fxString/string_evaluations.py
is_valid_sedol(text: str) -> bool
¶
Validate a SEDOL (Stock Exchange Daily Official List) code.
Description
A SEDOL is 7 characters: 6 alphanumeric characters (no vowels) followed by a weighted check digit. Weights are [1, 3, 1, 7, 3, 9].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The SEDOL code to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the SEDOL is valid. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
Usage Example
is_valid_sedol("0263494") True
Complexity: O(1)
Source code in shortfx/fxString/string_evaluations.py
is_valid_semver(text: str) -> bool
¶
Validate a Semantic Versioning string (SemVer 2.0.0).
Format: MAJOR.MINOR.PATCH[-prerelease][+build].
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
String to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
Example
is_valid_semver("1.2.3-alpha.1+build.42") True
Complexity: O(n)
Source code in shortfx/fxString/string_evaluations.py
is_valid_swift_bic(text: str) -> bool
¶
Validates a SWIFT/BIC (Business Identifier Code) string.
Description
Checks that the code conforms to the ISO 9362 format:
4 letters (bank) + 2 letters (country) + 2 alphanumeric
(location) + optional 3 alphanumeric (branch or XXX).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The SWIFT/BIC code to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the code matches the SWIFT/BIC format. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
Usage Example
is_valid_swift_bic("DEUTDEFF") True is_valid_swift_bic("DEUTDEFF500") True
Complexity: O(1)
Source code in shortfx/fxString/string_evaluations.py
is_valid_uuid(text: str) -> bool
¶
Validate a UUID string (versions 1-5).
Expects the canonical 8-4-4-4-12 hex format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
String to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
Example
is_valid_uuid("550e8400-e29b-41d4-a716-446655440000") True
Complexity: O(1)
Source code in shortfx/fxString/string_evaluations.py
is_valid_vin(text: str) -> bool
¶
Validate a VIN (Vehicle Identification Number).
Description
A VIN is 17 characters (letters and digits, excluding I, O, Q). Position 9 is a check digit computed by transliterating each character to a value, multiplying by positional weights, summing, and taking mod 11 (10 → 'X').
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The VIN to validate. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the VIN is valid. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
Usage Example
is_valid_vin("1M8GDM9AXKP042788") True
Complexity: O(1)
Source code in shortfx/fxString/string_evaluations.py
parse_email(email_address: str) -> dict | None
¶
Parses an email address string and returns its username and domain.
This function expects a valid email address format containing a single '@' symbol. It splits the email into its two main components: the username and the domain.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
email_address
|
str
|
The email address string to be parsed. |
required |
Returns:
| Type | Description |
|---|---|
dict | None
|
dict | None: A dictionary with 'username' and 'domain' keys if the email is valid, otherwise None if the '@' symbol is not found. |
Example of use
parse_email("user@example.com") {'username': 'user', 'domain': 'example.com'} parse_email("another.user+tag@sub.domain.co.uk") {'username': 'another.user+tag', 'domain': 'sub.domain.co.uk'} parse_email("invalid-email") None
Source code in shortfx/fxString/string_evaluations.py
reading_time(text: str, words_per_minute: int = 200) -> float
¶
Estimates the reading time of a text in minutes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The input text. |
required |
words_per_minute
|
int
|
Average reading speed (default: 200 wpm). |
200
|
Returns:
| Type | Description |
|---|---|
float
|
Estimated reading time in minutes (rounded to 1 decimal). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
Example
reading_time("word " * 400) 2.0 reading_time("short text") 0.1
Complexity: O(n)
Source code in shortfx/fxString/string_evaluations.py
sentence_count(text: str) -> int
¶
Counts the number of sentences in a text string.
Sentences are detected by terminal punctuation (. ! ?).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The input text. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The estimated number of sentences. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
Example
sentence_count("Hello world. How are you? Fine!") 3 sentence_count("No punctuation") 1
Complexity: O(n)
Source code in shortfx/fxString/string_evaluations.py
smog_index(text: str) -> float
¶
Compute the SMOG readability index for English text.
Designed for texts with ≥ 30 sentences but works as an estimate on shorter texts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
English prose text. |
required |
Returns:
| Type | Description |
|---|---|
float
|
SMOG index. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
ValueError
|
If text has no sentences. |
Usage Example
round(smog_index('The cat sat on the mat.'), 1) 3.0
Complexity: O(n)
Source code in shortfx/fxString/string_evaluations.py
starts_with_substring(input_string: str, prefix: str, case_sensitive: bool = True) -> bool
¶
Checks if a string starts with a specific substring.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_string
|
str
|
The string to check. |
required |
prefix
|
str
|
The substring to look for at the beginning. |
required |
case_sensitive
|
bool
|
If True, the comparison is case-sensitive. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the string starts with the prefix, False otherwise. |
Examples:
starts_with_substring("hello world", "hello") returns True starts_with_substring("Hello World", "hello", case_sensitive=False) returns True starts_with_substring("filename.txt", "file") returns True starts_with_substring("data_123", "data_") returns True starts_with_substring("MyDocument", "document", case_sensitive=False) returns True starts_with_substring("MyDocument", "Doc") returns False
Source code in shortfx/fxString/string_evaluations.py
text_entropy(text: str) -> float
¶
Calculates Shannon entropy of a string in bits per character.
Measures the information density / randomness of the text. Higher values indicate more randomness; lower values more repetition or structure.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The input string to analyse. |
required |
Returns:
| Type | Description |
|---|---|
float
|
Shannon entropy in bits per character (0.0 for empty string). |
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
Example
round(text_entropy("aaaa"), 2) 0.0 round(text_entropy("abcd"), 2) 2.0
Complexity: O(n)
Source code in shortfx/fxString/string_evaluations.py
text_stats(text: str) -> dict
¶
Compute summary statistics for a text string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
Input text. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dict with keys: |
dict
|
|
Example
stats = text_stats("Hello world. How are you?") stats['words'] 5 stats['sentences'] 2
Complexity: O(n)
Source code in shortfx/fxString/string_evaluations.py
username_from_email(email_address: str) -> list[str] | None
¶
Extracts and returns a list of individual parts from an email's username.
This function first parses the email to get the username. It then splits the username by common delimiters such as periods (.), hyphens (-), and underscores (_), returning a list of these parts. This is useful for extracting components of a name or identifier from an email address.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
email_address
|
str
|
The full email address string. |
required |
Returns:
| Type | Description |
|---|---|
list[str] | None
|
list[str] | None: A list of strings representing the parts of the username, or None if the email address is invalid or cannot be parsed. |
Example of use
username_from_email("john.doe_123@example.com") ['john', 'doe', '123'] username_from_email("jane-smith@domain.net") ['jane', 'smith'] username_from_email("simpleuser@mail.org") ['simpleuser'] username_from_email("invalid-email-format") None username_from_email("another.user+tag@example.com") # Note: '+' is not split by default ['another', 'user+tag']
Source code in shortfx/fxString/string_evaluations.py
validate_nif_format_and_type(raw_nif_string: str, assume_spanish_if_no_prefix: bool = True) -> tuple[bool, str | None, str | None, str | None, str | None]
¶
Validates the format of a NIF (Spanish DNI/NIE/CIF or other European NIFs/VAT IDs).
This function performs initial normalization, extracts country prefixes, and checks the format against known patterns. For Spanish NIFs (DNI/NIE), it also performs a checksum validation. For other countries, it primarily validates the format using regular expressions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
raw_nif_string
|
str
|
The NIF string to validate. |
required |
assume_spanish_if_no_prefix
|
bool
|
If True, treats a string without a recognized country prefix as a potential Spanish NIF. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
tuple |
tuple[bool, str | None, str | None, str | None, str | None]
|
(is_valid, nif_type, country_name, country_code, cleaned_nif_value) - is_valid (bool): True if valid, False otherwise. - nif_type (str | None): 'DNI', 'NIE', 'CIF', 'NIF' (general), or None. - country_name (str | None): 'SPAIN', 'GERMANY', etc., or None. - country_code (str | None): 'ES', 'DE', etc., or None. - cleaned_nif_value (str | None): The NIF string without spaces, uppercase. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If 'raw_nif_string' is not a string. |
Example of use
Example using placeholder functions for DNI/NIE/CIF¶
>>> validate_nif_format_and_type("12345678Z")¶
(True, 'DNI', 'SPAIN', 'ES', 'ES12345678Z')¶
>>> validate_nif_format_and_type("PT123456789")¶
(True, 'NIF', 'PORTUGAL', 'PT', 'PT123456789')¶
>>> validate_nif_format_and_type("invalid-nif")¶
(False, None, None, None, None)¶
Source code in shortfx/fxString/string_evaluations.py
977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 | |
validate_substring_type(original_string: str, extract_method: str, expected_type: str, start_position: int = None, length: int = None, num_chars: int = None, date_format: str = None) -> tuple[bool, str, str]
¶
Extrae una subcadena y verifica si su contenido corresponde a un tipo de dato esperado.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
original_string
|
str
|
La cadena de la que se extraerá la subcadena. |
required |
extract_method
|
str
|
El método de extracción ('substring', 'left', 'right'). |
required |
expected_type
|
str
|
El tipo de dato esperado ('numeric', 'integer', 'alphabetic', 'alphanumeric', 'date', 'boolean'). |
required |
start_position
|
int
|
Posición inicial para 'substring'. |
None
|
length
|
int
|
Longitud para 'substring' o 'left'. |
None
|
num_chars
|
int
|
Número de caracteres para 'left' o 'right'. |
None
|
date_format
|
str
|
Formato esperado si expected_type es 'date' (ej. '%Y-%m-%d'). |
None
|
Returns:
| Type | Description |
|---|---|
tuple[bool, str, str]
|
tuple[bool, str, str]: Una tupla que contiene: - bool: True si la subcadena es del tipo esperado, False en caso contrario. - str: La subcadena extraída. - str: Un mensaje de estado o error. |
Raises:
| Type | Description |
|---|---|
ValueError
|
Si extract_method es inválido o faltan parámetros para la extracción. |
TypeError
|
Si los tipos de entrada no son correctos. |
Source code in shortfx/fxString/string_evaluations.py
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 | |
word_frequency(text: str) -> dict[str, int]
¶
Calculates the frequency of each word in a text string.
Words are split by whitespace and compared case-insensitively.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The input text. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, int]
|
A dictionary mapping each lowercase word to its count. |
Raises:
| Type | Description |
|---|---|
TypeError
|
If text is not a string. |
Example
word_frequency("the cat and the dog")
Complexity: O(n)