From 34129d1e81aee289102d289f2b724bb6b6ba2ce0 Mon Sep 17 00:00:00 2001 From: Ivandro Jao Date: Tue, 3 Dec 2024 21:38:38 +0000 Subject: [PATCH] Improve regex for detecting numeric separators Renamed and enhanced the regex to better match numeric values separated by punctuation with or without spaces. This change improves the text processing accuracy by adjusting how separators are recognized between numbers. The updated regex should cover more use cases in text parsing scenarios. Fixes #9052 Signed-off-by: Ivandro Jao --- src/libse/Common/Utilities.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libse/Common/Utilities.cs b/src/libse/Common/Utilities.cs index aada8425eb..ea95223fdc 100644 --- a/src/libse/Common/Utilities.cs +++ b/src/libse/Common/Utilities.cs @@ -25,7 +25,7 @@ public static class Utilities /// public static readonly char[] NewLineChars = { '\r', '\n' }; - private static readonly Regex NumberSeparatorNumberRegEx = new Regex(@"\b\d+[\.:;] \d+\b", RegexOptions.Compiled); + private static readonly Regex NumericSeparatorRegex = new Regex(@"\b\d+(?>[ ]+[\.:;][ ]*|[ ]*[\.:;][ ]+)\d+\b", RegexOptions.Compiled); private static readonly Regex RegexIsNumber = new Regex("^\\d+$", RegexOptions.Compiled); private static readonly Regex RegexIsEpisodeNumber = new Regex("^\\d+x\\d+$", RegexOptions.Compiled); private static readonly Regex RegexNumberSpacePeriod = new Regex(@"(\d) (\.)", RegexOptions.Compiled); @@ -2551,12 +2551,12 @@ public static string RemoveUnneededSpaces(string input, string language) text = text.Replace(" . ", ". "); } - var numberSeparatorNumberMatch = NumberSeparatorNumberRegEx.Match(text); + var numberSeparatorNumberMatch = NumericSeparatorRegex.Match(text); while (numberSeparatorNumberMatch.Success) { var spaceIdx = text.IndexOf(' ', numberSeparatorNumberMatch.Index); text = text.Remove(spaceIdx, 1); - numberSeparatorNumberMatch = NumberSeparatorNumberRegEx.Match(text); + numberSeparatorNumberMatch = NumericSeparatorRegex.Match(text); } return text;