When checking comments for activity names and ref regexes, stop consuming the non-word characters each side of the match. This was causing multiple references next to each other in a list to skip every even numbered reference.

This commit is contained in:
Ian Renton
2026-09-25 07:54:43 +01:00
parent e2267ba27f
commit 7417140a3d
9 changed files with 23 additions and 23 deletions
+8 -8
View File
@@ -283,21 +283,21 @@ class Spot:
activity = self.activity_refs[0].activity.upper()
regex = get_ref_regex_for_activity(activity)
if regex:
all_comment_ref_matches = re.finditer(r"(^|\W)(" + regex + r")($|\W)", self.comment, re.IGNORECASE)
all_comment_ref_matches = re.finditer(r"(?<!\w)(" + regex + r")(?!\w)", self.comment, re.IGNORECASE)
for ref_match in all_comment_ref_matches:
self._append_activity_ref_if_missing(
ActivityRef(id=ref_match.group(2).upper(), activity=activity)
ActivityRef(id=ref_match.group(1).upper(), activity=activity)
)
# See if the comment looks like it contains any activities (and optionally activity references) that we
# can add to the spot. This should catch cluster spot comments like "POTA GB-0001 WWFF GFF-0001" and e.g.
# POTA comments like "also WWFF GFF-0001".
if self.comment:
activity_matches = re.finditer(r"(^|\W)" + ANY_ACTIVITY_REGEX + r"($|\W)", self.comment, re.IGNORECASE)
activity_matches = re.finditer(r"(?<!\w)" + ANY_ACTIVITY_REGEX + r"(?!\w)", self.comment, re.IGNORECASE)
for activity_match in activity_matches:
# First of all, add the activity to this spot's list of activities. This covers
# things like cluster spots where the comment is just "POTA".
found_activity = get_activity_name_from_comment_name(activity_match.group(2))
found_activity = get_activity_name_from_comment_name(activity_match.group(1))
self.add_activity(found_activity)
# Now look to see if that activity name was followed by something that looks like a reference ID
@@ -305,13 +305,13 @@ class Spot:
found_activity_info = get_activity_by_name(found_activity)
if found_activity_info and found_activity_info.has_refs and found_activity_info.ref_regex:
ref_matches = re.finditer(
r"(^|\W)" + found_activity + r"([ -])(" + found_activity_info.ref_regex + r")($|\W)",
r"(?<!\w)" + found_activity + r"[ -](" + found_activity_info.ref_regex + r")(?!\w)",
self.comment,
re.IGNORECASE,
)
for ref_match in ref_matches:
self._append_activity_ref_if_missing(
ActivityRef(id=ref_match.group(3).upper(), activity=found_activity)
ActivityRef(id=ref_match.group(1).upper(), activity=found_activity)
)
# See if the comment looks like it contains any activity references *without* the corresponding activity
@@ -321,14 +321,14 @@ class Spot:
for activity in ACTIVITIES.values():
if activity.has_refs and activity.refs_globally_unique and activity.ref_regex:
ref_matches = re.finditer(
r"(^|\W)(" + activity.ref_regex + r")($|\W)", self.comment, re.IGNORECASE
r"(?<!\w)(" + activity.ref_regex + r")(?!\w)", self.comment, re.IGNORECASE
)
for ref_match in ref_matches:
# First of all, add the activity to this spot's list of activities. This covers things
# like cluster spots where the comment is just "OHFF-1234", now we know it's WWFF.
self.add_activity(activity.name)
self._append_activity_ref_if_missing(
ActivityRef(id=ref_match.group(2).upper(), activity=activity.name)
ActivityRef(id=ref_match.group(1).upper(), activity=activity.name)
)
# Fetch activity data. In case a particular API doesn't provide a full set of name, lat, lon & grid for a