From 2691888b2053828d4e8e7ad313d55dcc92fede1e Mon Sep 17 00:00:00 2001 From: Zefanja Jobse Date: Sun, 22 Sep 2024 20:24:27 +0200 Subject: [PATCH] use regex to match specificly a line with (verse) 2x|2 --- PlanningCenter to OPS/Actions/LyricsToFile.cs | 50 ++++++------------- 1 file changed, 16 insertions(+), 34 deletions(-) diff --git a/PlanningCenter to OPS/Actions/LyricsToFile.cs b/PlanningCenter to OPS/Actions/LyricsToFile.cs index 2e7bffa..ce56bae 100644 --- a/PlanningCenter to OPS/Actions/LyricsToFile.cs +++ b/PlanningCenter to OPS/Actions/LyricsToFile.cs @@ -10,39 +10,20 @@ namespace PlanningCenter_to_OPS.Actions { internal class LyricsToFile { - private static readonly string[] removed_if_in_line = { - "Vers", - "Vers 1", - "Vers 2", - "Vers 3", - "Vers 4", - "Vers 5", - "Verse", - "Verse 1", - "Verse 2", - "Verse 3", - "Verse 4", - "Verse 5", - "Couplet 1", - "Couplet 2", - "Couplet 3", - "Couplet 4", - "Couplet 5", - "(Bridge", - "Misc 1", - "Misc 2", - "Misc 3", - "Misc 4", - "Misc 5", - "(Pre-Chorus)", - "Pre-Chorus", - "INTERMEZZO", - "INTRO", - "(TAG)", - "(Interlude)", - "(REPEAT)", - "Verhoging", - }; + private static readonly List removed_if_line = [ + "vers", + "verse", + "couplet", + "bridge", + "misc", + "pre-Chorus", + "intermezzo", + "intro", + "tag", + "interlude", + "(repeat)", + "verhoging", + ]; private static readonly string[] remove_text = { "", @@ -106,7 +87,8 @@ internal static string Lyrics(string lyrics, List skip_list) mut_line = Regex.Replace(mut_line, item, ""); } // if value not in RemovedText or if added to skip_list - if (!removed_if_in_line.Any(s => mut_line.ToLower().Contains(s.ToLower())) || skip_list.Any(s => s == mut_line)) + var regex = new Regex(string.Format(@"^\b(?:{0})\b(| \d| \dx)$", string.Join("|", removed_if_line)), RegexOptions.Compiled); + if (!regex.Match(mut_line.Trim().ToLower()).Success || skip_list.Any(s => s == mut_line)) { // Use skiplist to make it a header item when needed if (skip_list.Contains(mut_line.Trim().ToLower().Replace(":", "") + ":"))