Skip to content

Regex filters containing a space or \s never match under the default ByWordAny option ("hello world" doesn't match "hello world") #122

Description

@matt-edmondson

What's wrong

DoesMatchRegex (TextFilter/TextFilter.cs ~L452) splits the text into words via ExtractTextTokens for ByWordAny/ByWordAll, then runs the regex against each word separately (~L488-496). The pattern isn't split. Since no single word ever contains whitespace, any regex that must match across whitespace (a literal space, \s, a phrase) can never match. Filter/IsMatch default to TextFilterMatchOptions.ByWordAny, so this is the out-of-the-box behavior.

Failure scenario (verified with a console app against the net10.0 build)

TextFilter.IsMatch("hello world", "hello world", TextFilterType.Regex); // False
TextFilter.IsMatch("hello world", "o w",         TextFilterType.Regex); // False

Only ByWholeString matches. In a regex filter box with default options, typing New York or \d+ items hides every item, even though the regex hint says the text must match the pattern.

Suggested fix

Under ByWordAny, also try the pattern against the whole text: regex.IsMatch(text) || tokens.Any(regex.IsMatch). Keeping the per-word check means word-anchored patterns like ^world keep matching. (For ByWordAll the per-word semantics are arguably intended; at minimum document that whitespace-spanning patterns need ByWholeString there.)

Acceptance criteria

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions