Skip to content

Regex filter never matches blank text under the default ByWordAny: IsMatch(" ", @"\s", Regex) and IsMatch("", "^$", Regex) return false #193

Open

Description

@matt-edmondson

What's wrong

Under the default TextFilterMatchOptions.ByWordAny, a regex filter can't match text that is empty or only whitespace, even when the pattern is written to match exactly that:

Call Result Expected
IsMatch(" ", @"\s", TextFilterType.Regex) false true
IsMatch("a b", @"\s", TextFilterType.Regex) true true
IsMatch(" ", @"\s", TextFilterType.Regex, ByWholeString) true true
IsMatch("", "^$", TextFilterType.Regex) false true
IsMatch("", "^$", TextFilterType.Regex, ByWholeString) true true

So a "find the blank entries" filter such as ^\s*$ or \s+ misses exactly the entries it is looking for, but only under the default option. The same pattern does match whitespace when the text also contains a word.

I checked this with a scratch MSTest against main at 5f420d9.

Cause

In DoesMatchRegex (TextFilter/TextFilter.cs:735-746), the early return for blank text comes before the ByWordAny whole-text attempt:

if (textTokens.Count == 0)
{
    return false;          // added for #107/#109 so ByWordAll isn't vacuously true
}

if (textFilterMatchOptions is TextFilterMatchOptions.ByWordAny && IsMatchWithinTimeout(ref activeRegex, cacheKey, text))
{
    return true;           // added for #125: patterns that span whitespace match the whole text
}

Blank text splits into zero words, so the function returns before the whole text is ever matched. The early return was only needed for ByWordAll, where Enumerable.All over an empty set is vacuously true.

Suggested fix

Move the ByWordAny whole-text check above the textTokens.Count == 0 return, or limit that return to ByWordAll. Either way, #107/#109 stays fixed: under ByWordAll, blank text still matches nothing.

Acceptance criteria

Activity

  1. matt-edmondson commented on Nov 6, 2026

    @matt-edmondson
    ContributorAuthor

    Triage


    Generated by Claude Code

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