Find matching description for a scan value with Regex group support.
Regex patterns support capture groups that can be referenced in the description using standard regex backreferences (\1, \2, etc.) via match.expand().
Example: Pattern: r"(\d{7})" Input: "1234567" Description template: "RIC: \1" Result: "RIC: 1234567"
109 def _find_description(self, descriptor_key, scan_value, bw_packet):
110 r"""!Find matching description for a scan value with Regex group support.
111
112 The search is performed in two passes for performance optimization:
113 1. First pass: Check for exact string matches (fast, no regex compilation)
114 2. Second pass: Check regex patterns only if no exact match was found
115
116 Regex patterns support capture groups that can be referenced in the description
117 using standard regex backreferences (\1, \2, etc.) via match.expand().
118
119 Example:
120 Pattern: r"(\d{7})"
121 Input: "1234567"
122 Description template: "RIC: \1"
123 Result: "RIC: 1234567"
124
125 @param descriptor_key: Cache key identifying the descriptor configuration
126 @param scan_value: Value to search for in the descriptor cache
127 @param bw_packet: BOSWatch packet for wildcard replacement
128 @return: Matched description string or None if no match found
129 """
130
131 descriptions = self.unified_cache.get(descriptor_key, [])
132 scan_value_str = str(scan_value).strip()
133
134
135
136 for desc in descriptions:
137 if not desc.get('isRegex', False):
138 if desc['for'] == scan_value_str:
139 description_text = desc.get('add', '')
140 final_description = self._replace_wildcards(description_text, bw_packet)
141 return final_description
142
143
144
145 for desc in descriptions:
146 if desc.get('isRegex', False):
147 match_pattern = desc.get('for', '')
148 try:
149 match = re.search(match_pattern, scan_value_str)
150 if match:
151 description_text = desc.get('add', '')
152
153
154
155 expanded_description = match.expand(description_text)
156 final_description = self._replace_wildcards(expanded_description, bw_packet)
157 return final_description
158 except re.error as e:
159 logging.error("Invalid regex pattern '%s': %s", match_pattern, e)
160
161 return None
162