Skip to content

Commit

Permalink
regex support match whole word
Browse files Browse the repository at this point in the history
  • Loading branch information
celeron533 committed Jan 26, 2024
1 parent 899516e commit b5872fa
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions DicomGrepCore/Services/SearchService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,21 @@ private bool CompareString(string refString, string testString, bool caseSensiti
options |= RegexOptions.IgnoreCase;
}

if (wholeWord)
{
// regex match start
if (!testString.StartsWith('^'))
{
testString = "^" + testString;
}

// regex match end
if (!testString.EndsWith('$'))
{
testString += "$";
}
}

result = Regex.IsMatch(refString, testString, options);
break;
}
Expand Down

0 comments on commit b5872fa

Please sign in to comment.