Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve regex for detecting numeric separators #9058

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/libse/Common/Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static class Utilities
/// </summary>
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);
Expand Down Expand Up @@ -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;
Expand Down