@@ -137,6 +137,14 @@ def _get_all_available_keys(self) -> set[str]:
137137
138138 return keys
139139
140+ def _key_matches (self , match_key : str , key : str ) -> bool :
141+ if key == match_key :
142+ return True
143+ # "++" can cause re.compile to fail. Since it is never a valid regex expression
144+ # it is safe to escape it to prevent the error.
145+ match_key = match_key .replace ("++" , r"\+\+" )
146+ return bool (re .fullmatch (match_key , key ))
147+
140148 def _get_matching_keys (self , key_or_keys : str | set [str ]) -> set [str ]:
141149 """Get keys that match the given pattern(s)."""
142150 all_keys = self ._get_all_available_keys ()
@@ -155,9 +163,7 @@ def _get_matching_keys(self, key_or_keys: str | set[str]) -> set[str]:
155163 matches_found = False
156164
157165 # Check for exact match
158- if any (
159- k for k in all_keys if k == attr_key or re .fullmatch (attr_key , k )
160- ):
166+ if any (k for k in all_keys if self ._key_matches (attr_key , k )):
161167 normalized_keys .add (attr_key )
162168 matches_found = True
163169
@@ -184,9 +190,7 @@ def _get_matching_keys(self, key_or_keys: str | set[str]) -> set[str]:
184190 return {
185191 matched
186192 for regex_key in normalized_keys
187- for matched in [
188- k for k in all_keys if k == regex_key or re .fullmatch (regex_key , k )
189- ]
193+ for matched in [k for k in all_keys if self ._key_matches (str (regex_key ), k )]
190194 }
191195
192196 def mark_read (self , key_or_keys : str | set [str ]) -> None :
@@ -266,7 +270,7 @@ def _apply_regex_filter(
266270 ) -> set [str ]:
267271 """Apply regex filter to attribute keys if provided."""
268272 if regex :
269- return {k for k in attribute_keys if re . fullmatch (regex , k )}
273+ return {k for k in attribute_keys if self . _key_matches (regex , k )}
270274 return attribute_keys
271275
272276 def _process_attr_key (
0 commit comments