Let a regex that spans whitespace match under ByWordAny [patch] - #125
Merged
Merged
Conversation
DoesMatchRegex split the text into words for ByWordAny and ByWordAll and ran the pattern against each word. No word contains whitespace, so a pattern such as "hello world", "o\sw" or "New York" could never match, and ByWordAny is the default for Filter and IsMatch. Under ByWordAny the pattern is now tried against the whole text first, then against each word, so word-anchored patterns like "^world" still match. Both evaluations share the existing timeout handling. ByWordAll keeps its per-word meaning, and the remarks now say that a pattern spanning whitespace needs ByWholeString there. Fixes #122 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01M9aefrfAYJpanQVrUuFpJh
|
This was referenced Sep 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes #122
Problem
For
ByWordAnyandByWordAll,DoesMatchRegexsplit the text into words and ran the pattern against each word separately. No word contains whitespace, so any pattern that has to match across it could never match. That includeshello world,o\swandNew York.ByWordAnyis the default forFilterandIsMatch, so in a regex filter box with default options, typing a phrase hid every item.Change
All in
TextFilter/TextFilter.cs:ByWordAny: the pattern is now tried against the whole text, then against each word, which is the fix the triage suggested. Word-anchored patterns like^worldstill matchhello worldthrough the per-word pass.try/catch (RegexMatchTimeoutException)moved into a privateIsMatchWithinTimeout. The whole-text evaluation and the per-word evaluations share it, so a pattern that times out on the whole text still reports no match rather than throwing.ByWordAllunchanged: it keeps its per-word meaning. TheDoesMatchRegexremarks now say that a pattern spanning whitespace needsByWholeStringthere. That is the "document it" option from the triage, and it doesn't change behaviour for existingByWordAllcallers.falsebefore either pass runs.Timeout budget: for
ByWordAny, one catastrophic pattern now costs up to one extra timeout per item: the whole-text attempt on top of the per-word attempts. #118 tracks the per-word timeout budget, and fixing it there covers this evaluation too.Tests
IsMatchRegexSpanningWhitespaceMatchesUnderTheDefaultscovers the two acceptance cases from the issue (hello worldando\sw), pluso w,New Yorkand\d+\s+items.FilterRegexSpanningWhitespaceKeepsMatchingItemsUnderTheDefaultsIsMatchRegexByWordAnyStillMatchesAWordAnchoredPatternchecks that^worldandhello$still match, and that a phrase with a doubled space doesn't.DoesMatchRegexByWordAllStillRequiresEveryWordToMatchOnItsOwnpins the documentedByWordAllbehaviour.With the change to
TextFilter.csreverted, the 6 whitespace-spanning cases fail. With it, the full suite passes (123/123 on net10.0), and the library builds for every target.This PR also edits
DoesMatchRegex, like #121, but on different lines. Whichever of the two merges second may need a trivial rebase.🤖 Generated with Claude Code
https://claude.ai/code/session_01M9aefrfAYJpanQVrUuFpJh
Generated by Claude Code