function has_wuxi_coding_v1
Validates whether a filename starts with a Wuxi coding pattern, which consists of numbers separated by dots (e.g., '2.13.4.1.2').
/tf/active/vicechatdev/mailsearch/upload_non_wuxi_coded.py
17 - 20
simple
Purpose
This function is designed to identify files that follow a specific hierarchical numbering convention known as 'Wuxi coding'. It checks if the filename begins with a pattern of one or more digits followed by additional dot-separated digit sequences. This is commonly used in document management systems, version control, or organizational file naming schemes where hierarchical numeric identifiers are used to categorize or order files.
Source Code
def has_wuxi_coding(filename):
"""Check if filename starts with wuxi coding pattern (e.g., '2.13.4.1.2')"""
pattern = r'^\d+(?:\.\d+)+'
return bool(re.match(pattern, filename))
Parameters
| Name | Type | Default | Kind |
|---|---|---|---|
filename |
- | - | positional_or_keyword |
Parameter Details
filename: A string representing the filename (or file path) to check. Can be a full path or just a filename. The function only examines the beginning of the string to determine if it matches the Wuxi coding pattern. Expected to be a string type, though no explicit type checking is performed.
Return Value
Returns a boolean value. True if the filename starts with the Wuxi coding pattern (one or more digits followed by at least one dot and more digits, e.g., '1.2', '2.13.4.1.2'). False if the pattern is not found at the start of the filename or if the input doesn't match the expected format.
Dependencies
re
Required Imports
import re
Usage Example
import re
def has_wuxi_coding(filename):
"""Check if filename starts with wuxi coding pattern (e.g., '2.13.4.1.2')"""
pattern = r'^\d+(?:\.\d+)+'
return bool(re.match(pattern, filename))
# Example usage
print(has_wuxi_coding('2.13.4.1.2_document.pdf')) # True
print(has_wuxi_coding('1.2.3_report.docx')) # True
print(has_wuxi_coding('document_2.13.4.pdf')) # False
print(has_wuxi_coding('123_file.txt')) # False (no dots)
print(has_wuxi_coding('1.2')) # True
print(has_wuxi_coding('abc.123.456')) # False (doesn't start with digit)
Best Practices
- The function only checks if the filename STARTS with the Wuxi coding pattern; it does not validate the entire filename structure
- The pattern requires at least one dot separator (e.g., '1.2' is valid, but '123' alone is not)
- Consider sanitizing or validating the input to ensure it's a string before calling this function to avoid potential errors
- The function works on the raw filename string, so if passing a full file path, the path components will be included in the check
- For file path inputs, consider using os.path.basename() or Path().name to extract just the filename before checking
- The regex pattern is case-insensitive to digits but will not match if there are leading spaces or other characters
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function has_wuxi_coding 97.7% similar
-
function extract_document_code_v1 58.5% similar
-
function find_best_folder 56.6% similar
-
function scan_wuxi2_folder_v1 53.2% similar
-
function scan_wuxi2_folder 52.5% similar