Skip to content

Commit

Permalink
Merge pull request #285 from hakonhagland/upd_addkeyword2
Browse files Browse the repository at this point in the history
Use more accurate regex in add-keyword script
  • Loading branch information
gdfldm authored Jun 6, 2024
2 parents 9c8ff37 + f9569ae commit 3d40a6f
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion scripts/python/src/fodt/add_keyword.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ def endElement(self, name: str):

def extract_keyword_name(self, href: str) -> str:
# Assume href starts with "#xxx.yyy.zzz.KEYWORD_NAME<space>"
if m:= re.match(r"#\d+\.\d+\.\d+\.(\w+)(?:\s+|$)", href):
# or "#xxx.yyy.zzz.KEYWORD_NAME|outline"
# KEYWORD_NAME can contain letters, numbers, and optionally a trailing hyphen or en-dash
if m:= re.match(r"#\d+\.\d+\.\d+\.(\w+[\-–]?)(?:\s+|$|\|outline$)", href):
return m.group(1)
else:
return '<NOT FOUND>'
Expand Down

0 comments on commit 3d40a6f

Please sign in to comment.