From 97187260c19a2e6e6b096931343e8c0ae3c2ff07 Mon Sep 17 00:00:00 2001 From: "(quasar) nebula" Date: Fri, 21 Jun 2024 19:07:10 -0300 Subject: data: factor out date matching in commentary heading --- src/util/wiki-data.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/util/wiki-data.js b/src/util/wiki-data.js index 8c318d02..aa7f1f56 100644 --- a/src/util/wiki-data.js +++ b/src/util/wiki-data.js @@ -89,8 +89,12 @@ export function getKebabCase(name) { // This regular expression *doesn't* match bodies, which will need to be parsed // out of the original string based on the indices matched using this. // + +const dateRegex = groupName => + String.raw`(?<${groupName}>[a-zA-Z]+ [0-9]{1,2}, [0-9]{4,4}|[0-9]{1,2} [^,]*[0-9]{4,4}|[0-9]{1,4}[-/][0-9]{1,4}[-/][0-9]{1,4})`; + const commentaryRegexRaw = - String.raw`^(?.+?)(?:\|(?.+))?:<\/i>(?: \((?(?:.*?(?=,|\)[^)]*$))*?)(?:,? ?(?[a-zA-Z]+ [0-9]{1,2}, [0-9]{4,4}|[0-9]{1,2} [^,]*[0-9]{4,4}|[0-9]{1,4}[-/][0-9]{1,4}[-/][0-9]{1,4}))?(?: (?captured|accessed) (?[a-zA-Z]+ [0-9]{1,2}, [0-9]{4,4}|[0-9]{1,2} [^,]*[0-9]{4,4}|[0-9]{1,4}[-/][0-9]{1,4}[-/][0-9]{1,4}))?\))?`; + String.raw`^(?.+?)(?:\|(?.+))?:<\/i>(?: \((?(?:.*?(?=,|\)[^)]*$))*?)(?:,? ?${dateRegex('date')})?(?: (?captured|accessed) ${dateRegex('accessDate')})?\))?`; export const commentaryRegexCaseInsensitive = new RegExp(commentaryRegexRaw, 'gmi'); export const commentaryRegexCaseSensitive = -- cgit 1.3.0-6-gf8a5