mirror of
https://github.com/Tyrrrz/DiscordChatExporter.git
synced 2026-02-14 15:53:30 -07:00
Make contains filter match on spaces and input boundaries, as well as word boundaries
Closes #909
This commit is contained in:
parent
92cf886eab
commit
612c6d37a4
|
|
@ -10,11 +10,19 @@ internal class ContainsMessageFilter : MessageFilter
|
||||||
|
|
||||||
public ContainsMessageFilter(string text) => _text = text;
|
public ContainsMessageFilter(string text) => _text = text;
|
||||||
|
|
||||||
|
// Match content within word boundaries, between spaces, or as the whole input.
|
||||||
|
// For example, "max" shouldn't match on content "our maximum effort",
|
||||||
|
// but should match on content "our max effort".
|
||||||
|
// Also, "(max)" should match on content "our (max) effort", even though
|
||||||
|
// parentheses are not considered word characters.
|
||||||
|
// https://github.com/Tyrrrz/DiscordChatExporter/issues/909
|
||||||
private bool IsMatch(string? content) =>
|
private bool IsMatch(string? content) =>
|
||||||
!string.IsNullOrWhiteSpace(content) &&
|
!string.IsNullOrWhiteSpace(content) &&
|
||||||
Regex.IsMatch(
|
Regex.IsMatch(
|
||||||
content,
|
content,
|
||||||
"\\b" + Regex.Escape(_text) + "\\b",
|
@"(?=\b|\s|^)" +
|
||||||
|
Regex.Escape(_text) +
|
||||||
|
@"(?=\b|\s|$)",
|
||||||
RegexOptions.IgnoreCase | RegexOptions.CultureInvariant
|
RegexOptions.IgnoreCase | RegexOptions.CultureInvariant
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ internal static class FilterGrammar
|
||||||
.Named("has:<value>");
|
.Named("has:<value>");
|
||||||
|
|
||||||
// Make sure that property-based filters like 'has:link' don't prevent text like 'hello' from being parsed.
|
// Make sure that property-based filters like 'has:link' don't prevent text like 'hello' from being parsed.
|
||||||
// https://github.com/Tyrrrz/DiscordChatExporter/issues/909
|
// https://github.com/Tyrrrz/DiscordChatExporter/issues/909#issuecomment-1227575455
|
||||||
private static readonly TextParser<MessageFilter> PrimitiveFilter =
|
private static readonly TextParser<MessageFilter> PrimitiveFilter =
|
||||||
Parse.OneOf(
|
Parse.OneOf(
|
||||||
FromFilter,
|
FromFilter,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue