ktsu.TextFilter 1.5.4

ktsu.TextFilter

A .NET library for filtering text using glob patterns, regular expressions, and fuzzy matching

License NuGet NuGet Downloads Build Status GitHub Stars

Introduction

ktsu.TextFilter is a .NET library that provides methods for filtering text based on different filter types and match options. It supports glob patterns, regular expressions, and fuzzy matching to help you efficiently filter and search through collections of strings.

Features

  • Glob Pattern Matching: Filter text using glob patterns with optional, required, and excluded tokens.
  • Regular Expression Matching: Filter text using regular expressions.
  • Fuzzy Matching: Rank text based on how well it matches a fuzzy pattern.
  • Customizable Match Options: Match by whole string, all words, or any word.

Installation

Package Manager Console

Install-Package ktsu.TextFilter

.NET CLI

dotnet add package ktsu.TextFilter

Package Reference

<PackageReference Include="ktsu.TextFilter" Version="x.y.z" />

Usage Examples

Basic Example

using ktsu.TextFilter;

string text = "Hello, World!";
string pattern = "Hello*";

bool isMatch = TextFilter.Match(text, pattern);

Filtering Collections

using ktsu.TextFilter;

string[] texts = new string[] { "Hello, World!", "Goodbye, World!" };
string pattern = "Hello*";

IEnumerable<string> matches = TextFilter.Filter(texts, pattern);

Ranking Results

using ktsu.TextFilter;

string[] texts = new string[] { "Hello, World!", "Goodbye, World!" };
string pattern = "Hello";

IEnumerable<string> ranked = TextFilter.Rank(texts, pattern);

Advanced Usage

Match Options

You can customize how matching is performed using the MatchOptions enum:

using ktsu.TextFilter;

string text = "Hello beautiful world";
string pattern = "hello world";

// Match by any word in the pattern
bool anyWordMatch = TextFilter.Match(text, pattern, MatchOptions.AnyWord);

// Match by all words in the pattern
bool allWordsMatch = TextFilter.Match(text, pattern, MatchOptions.AllWords);

// Match the entire string
bool wholeStringMatch = TextFilter.Match(text, pattern, MatchOptions.WholeString);

Filter Types

TextFilter supports different filter types:

using ktsu.TextFilter;

string text = "Hello, World!";
string globPattern = "Hello*";
string regexPattern = "^Hello";

// Glob pattern matching
bool globMatch = TextFilter.Match(text, globPattern, filterType: FilterType.Glob);

// Regular expression matching
bool regexMatch = TextFilter.Match(text, regexPattern, filterType: FilterType.Regex);

// Fuzzy matching
bool fuzzyMatch = TextFilter.Match(text, "Helo", filterType: FilterType.Fuzzy);

API Reference

TextFilter Class

The primary class for text filtering operations.

Methods

Name Return Type Description
Match(string text, string pattern, MatchOptions options = MatchOptions.WholeString, FilterType filterType = FilterType.Glob) bool Tests if the input text matches the specified pattern
Filter(IEnumerable<string> texts, string pattern, MatchOptions options = MatchOptions.WholeString, FilterType filterType = FilterType.Glob) IEnumerable<string> Returns all texts that match the pattern
Rank(IEnumerable<string> texts, string pattern, MatchOptions options = MatchOptions.WholeString) IEnumerable<string> Returns texts ranked by how well they match the pattern

Enums

MatchOptions

Value Description
WholeString Match the entire string against the pattern
AllWords Match all words in the pattern against the string
AnyWord Match any word in the pattern against the string

FilterType

Value Description
Glob Use glob pattern matching
Regex Use regular expression matching
Fuzzy Use fuzzy matching

Contributing

Contributions are welcome! For feature requests, bug reports, or questions, please open an issue on GitHub. If you would like to contribute code, please open a pull request with your changes.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgements

Showing the top 20 packages that depend on ktsu.TextFilter.

Packages Downloads
ktsu.ImGui.Popups
Package Description
19
ktsu.ImGui.Widgets
Package Description
18
ktsu.ImGui.Popups
Package Description
18
ktsu.ImGui.Widgets
Package Description
17
ktsu.ImGui.Popups
Package Description
17
ktsu.ImGui.Popups
Package Description
16
ktsu.ImGui.Widgets
Package Description
16
ktsu.ImGui.Popups
Package Description
15
ktsu.ImGui.Widgets
Package Description
15
ktsu.ImGui.Widgets
Package Description
14

## v1.5.4 (patch) Changes since v1.5.3: - Refactor TextFilter and update CI/CD workflow; streamline regex handling, improve test cases, and enhance build configuration with optional NuGet and Ktsu package keys. ([@matt-edmondson](https://github.com/matt-edmondson)) - Update .editorconfig, .gitignore, .gitattributes, .mailmap, and .runsettings; modify settings for code style, add SpecStory files to .gitignore, and streamline .runsettings for coverage output. ([@matt-edmondson](https://github.com/matt-edmondson)) ## v1.5.3 (patch) Changes since v1.5.2: - Update package references in TextFilter.csproj ([@matt-edmondson](https://github.com/matt-edmondson)) ## v1.5.3-pre.17 (prerelease) Changes since v1.5.3-pre.16: - Sync .gitattributes ([@ktsu[bot]](https://github.com/ktsu[bot])) - Merge remote-tracking branch 'refs/remotes/origin/main' ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync .mailmap ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync .gitignore ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync .runsettings ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync scripts\PSBuild.psm1 ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync .editorconfig ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.5.3-pre.16 (prerelease) Changes since v1.5.3-pre.15: - Sync .gitattributes ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync .gitignore ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync .editorconfig ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync scripts\PSBuild.psm1 ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync .runsettings ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync .mailmap ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.5.3-pre.15 (prerelease) Changes since v1.5.3-pre.14: ## v1.5.3-pre.14 (prerelease) Changes since v1.5.3-pre.13: ## v1.5.3-pre.13 (prerelease) Changes since v1.5.3-pre.12: ## v1.5.3-pre.12 (prerelease) Changes since v1.5.3-pre.11: ## v1.5.3-pre.11 (prerelease) Changes since v1.5.3-pre.10: ## v1.5.3-pre.10 (prerelease) Changes since v1.5.3-pre.9: ## v1.5.3-pre.9 (prerelease) Changes since v1.5.3-pre.8: ## v1.5.3-pre.8 (prerelease) Changes since v1.5.3-pre.7: ## v1.5.3-pre.7 (prerelease) Changes since v1.5.3-pre.6: ## v1.5.3-pre.6 (prerelease) Changes since v1.5.3-pre.5: ## v1.5.3-pre.5 (prerelease) Changes since v1.5.3-pre.4: ## v1.5.3-pre.4 (prerelease) Changes since v1.5.3-pre.3: ## v1.5.3-pre.3 (prerelease) Changes since v1.5.3-pre.2: ## v1.5.3-pre.2 (prerelease) Changes since v1.5.3-pre.1: ## v1.5.3-pre.1 (prerelease) Incremental prerelease update. ## v1.5.2 (patch) Changes since v1.5.1: - Enhance README with detailed usage examples and API reference; update project SDK references in .csproj files. ([@matt-edmondson](https://github.com/matt-edmondson)) - Remove obsolete build configuration files and scripts, including Directory.Build.props, Directory.Build.targets, and various PowerShell scripts for metadata and version management. ([@matt-edmondson](https://github.com/matt-edmondson)) ## v1.5.2-pre.2 (prerelease) Changes since v1.5.2-pre.1: - Sync .runsettings ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync .github\workflows\dotnet.yml ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync .editorconfig ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.5.2-pre.1 (prerelease) Incremental prerelease update. ## v1.5.1 (patch) Changes since v1.5.0: - Update packages ([@matt-edmondson](https://github.com/matt-edmondson)) ## v1.5.0 (minor) Changes since v1.4.0: - Add LICENSE template ([@matt-edmondson](https://github.com/matt-edmondson)) - Update packages ([@matt-edmondson](https://github.com/matt-edmondson)) ## v1.4.1 (patch) Changes since v1.4.0: - Update packages ([@matt-edmondson](https://github.com/matt-edmondson)) ## v1.4.1-pre.3 (prerelease) Changes since v1.4.1-pre.2: - Sync scripts\make-version.ps1 ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync scripts\make-changelog.ps1 ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.4.1-pre.2 (prerelease) Changes since v1.4.1-pre.1: - Sync .gitignore ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync .editorconfig ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync scripts\make-changelog.ps1 ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync scripts\make-version.ps1 ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync Directory.Build.targets ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.4.1-pre.1 (prerelease) Incremental prerelease update. ## v1.4.0 (minor) Changes since v1.3.0: - Apply new editorconfig ([@matt-edmondson](https://github.com/matt-edmondson)) ## v1.3.2-pre.26 (prerelease) Changes since v1.3.2-pre.25: - Bump Microsoft.DotNet.ILCompiler in the microsoft group ([@dependabot[bot]](https://github.com/dependabot[bot])) ## v1.3.2-pre.25 (prerelease) Changes since v1.3.2-pre.24: - Sync scripts\make-version.ps1 ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync scripts\make-changelog.ps1 ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.3.2-pre.24 (prerelease) Changes since v1.3.2-pre.23: - Sync .github\workflows\dotnet.yml ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.3.2-pre.23 (prerelease) Changes since v1.3.2-pre.22: - Sync scripts\make-changelog.ps1 ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync scripts\make-version.ps1 ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.3.2-pre.22 (prerelease) Changes since v1.3.2-pre.21: - Sync .github\workflows\dotnet.yml ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.3.2-pre.21 (prerelease) Changes since v1.3.2-pre.20: - Sync .github\workflows\dotnet.yml ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.3.2-pre.20 (prerelease) Changes since v1.3.2-pre.19: ## v1.3.2-pre.19 (prerelease) Changes since v1.3.2-pre.18: ## v1.3.2-pre.18 (prerelease) Changes since v1.3.2-pre.17: - Bump MSTest from 3.7.2 to 3.7.3 ([@dependabot[bot]](https://github.com/dependabot[bot])) ## v1.3.2-pre.17 (prerelease) Changes since v1.3.2-pre.16: ## v1.3.2-pre.16 (prerelease) Changes since v1.3.2-pre.15: ## v1.3.2-pre.15 (prerelease) Changes since v1.3.2-pre.14: - Bump MSTest from 3.7.1 to 3.7.2 ([@dependabot[bot]](https://github.com/dependabot[bot])) ## v1.3.2-pre.14 (prerelease) Changes since v1.3.2-pre.13: - Bump coverlet.collector from 6.0.3 to 6.0.4 ([@dependabot[bot]](https://github.com/dependabot[bot])) ## v1.3.2-pre.13 (prerelease) Changes since v1.3.2-pre.12: ## v1.3.2-pre.12 (prerelease) Changes since v1.3.2-pre.11: ## v1.3.2-pre.11 (prerelease) Changes since v1.3.2-pre.10: - Bump Microsoft.DotNet.ILCompiler in the microsoft group ([@dependabot[bot]](https://github.com/dependabot[bot])) ## v1.3.2-pre.10 (prerelease) Changes since v1.3.2-pre.9: - Bump MSTest from 3.7.0 to 3.7.1 ([@dependabot[bot]](https://github.com/dependabot[bot])) ## v1.3.2-pre.9 (prerelease) Changes since v1.3.2-pre.8: ## v1.3.2-pre.8 (prerelease) Changes since v1.3.2-pre.7: ## v1.3.2-pre.7 (prerelease) Changes since v1.3.2-pre.6: - Sync .github\workflows\dotnet.yml ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.3.2-pre.6 (prerelease) Changes since v1.3.2-pre.5: - Sync scripts\make-changelog.ps1 ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync scripts\make-version.ps1 ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.3.2-pre.5 (prerelease) Changes since v1.3.2-pre.4: ## v1.3.2-pre.4 (prerelease) Changes since v1.3.2-pre.3: - Sync .github\workflows\dotnet.yml ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.3.2-pre.3 (prerelease) Changes since v1.3.2-pre.2: ## v1.3.2-pre.2 (prerelease) Changes since v1.3.2-pre.1: - Bump the ktsu group with 2 updates ([@dependabot[bot]](https://github.com/dependabot[bot])) ## v1.3.2-pre.1 (prerelease) Changes since v1.3.1: - Sync scripts\make-version.ps1 ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.3.1 (patch) Changes since v1.3.0: - Sync scripts\make-changelog.ps1 ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync .mailmap ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.3.0 (minor) Changes since v1.2.0: - Add test for DoesMatchGlob with partial filter ([@matt-edmondson](https://github.com/matt-edmondson)) - Properly handle partially constructed glob filters that have prefixes ([@matt-edmondson](https://github.com/matt-edmondson)) ## v1.2.0 (minor) Changes since v1.1.0: - Add unit tests for TextFilter regex and glob matching ([@matt-edmondson](https://github.com/matt-edmondson)) - Fix empty / invalid filter behaviour ([@matt-edmondson](https://github.com/matt-edmondson)) - Add scripts for automated metadata generation and project management ([@matt-edmondson](https://github.com/matt-edmondson)) - Renamed metadata files ([@matt-edmondson](https://github.com/matt-edmondson)) ## v1.1.5 (patch) No significant changes detected since v1.1.5-pre.7. ## v1.1.5-pre.7 (prerelease) Changes since v1.1.5-pre.6: - Add scripts for automated metadata generation and project management ([@matt-edmondson](https://github.com/matt-edmondson)) ## v1.1.5-pre.6 (prerelease) Changes since v1.1.5-pre.5: ## v1.1.5-pre.5 (prerelease) Changes since v1.1.5-pre.4: - Bump coverlet.collector from 6.0.2 to 6.0.3 ([@dependabot[bot]](https://github.com/dependabot[bot])) ## v1.1.5-pre.4 (prerelease) Changes since v1.1.5-pre.3: - Bump ktsu.Extensions from 1.2.14 to 1.3.1 in the ktsu group ([@dependabot[bot]](https://github.com/dependabot[bot])) ## v1.1.5-pre.3 (prerelease) Changes since v1.1.5-pre.2: ## v1.1.5-pre.2 (prerelease) Changes since v1.1.5-pre.1: - Sync .github\workflows\dotnet.yml ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync .github\workflows\dotnet.yml ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.1.5-pre.1 (prerelease) Incremental prerelease update. ## v1.1.4-pre.1 (prerelease) Changes since v1.1.3-pre.1: - Sync .github\workflows\dotnet.yml ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.1.3-pre.1 (prerelease) Changes since v1.1.2-pre.1: - Sync .github\workflows\dotnet.yml ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.1.2-pre.1 (prerelease) Changes since v1.1.1: - Renamed metadata files ([@matt-edmondson](https://github.com/matt-edmondson)) ## v1.1.1 (patch) Changes since v1.1.0: - Bump the ktsu group with 2 updates ([@dependabot[bot]](https://github.com/dependabot[bot])) ## v1.1.0 (minor) Changes since v1.0.0: - Replace LICENSE file with LICENSE.md and update copyright information ([@matt-edmondson](https://github.com/matt-edmondson)) - Update LICENSE file to LICENSE.md with MIT License ([@matt-edmondson](https://github.com/matt-edmondson)) - Add key selector support to Filter and Rank methods ([@matt-edmondson](https://github.com/matt-edmondson)) - Refactor test method names in TextFilterTests.cs ([@matt-edmondson](https://github.com/matt-edmondson)) - Update TextFilter library description ([@matt-edmondson](https://github.com/matt-edmondson)) ## v1.0.19 (patch) Changes since v1.0.18: - Sync icon.png ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.0.18 (patch) Changes since v1.0.17: - Sync Directory.Build.props ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.0.17 (patch) Changes since v1.0.16: - Sync Directory.Build.props ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.0.16 (patch) Changes since v1.0.15: - Sync Directory.Build.props ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.0.15 (patch) Changes since v1.0.14: - Replace LICENSE file with LICENSE.md and update copyright information ([@matt-edmondson](https://github.com/matt-edmondson)) ## v1.0.14 (patch) Changes since v1.0.13: - Sync Directory.Build.targets ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.0.13 (patch) Changes since v1.0.12: - Update LICENSE file to LICENSE.md with MIT License ([@matt-edmondson](https://github.com/matt-edmondson)) - Refactor test method names in TextFilterTests.cs ([@matt-edmondson](https://github.com/matt-edmondson)) ## v1.0.12 (patch) Changes since v1.0.11: - Bump ktsu.Extensions from 1.2.6 to 1.2.7 in the ktsu group ([@dependabot[bot]](https://github.com/dependabot[bot])) ## v1.0.11 (patch) Changes since v1.0.10: - Bump the ktsu group with 2 updates ([@dependabot[bot]](https://github.com/dependabot[bot])) ## v1.0.10 (patch) Changes since v1.0.9: - Sync .github\workflows\dotnet.yml ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.0.9 (patch) Changes since v1.0.8: - Sync .github\workflows\dotnet.yml ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.0.8 (patch) Changes since v1.0.7: ## v1.0.7 (patch) Changes since v1.0.6: ## v1.0.6 (patch) Changes since v1.0.5: ## v1.0.5 (patch) Changes since v1.0.4: - Sync Directory.Build.targets ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync Directory.Build.props ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.0.4 (patch) Changes since v1.0.3: ## v1.0.3 (patch) Changes since v1.0.2: ## v1.0.2 (patch) Changes since v1.0.1: - Sync Directory.Build.props ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync Directory.Build.props ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync Directory.Build.targets ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync .github\workflows\dotnet.yml ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync Directory.Build.targets ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync .github\workflows\dotnet.yml ([@ktsu[bot]](https://github.com/ktsu[bot])) - Sync Directory.Build.targets ([@ktsu[bot]](https://github.com/ktsu[bot])) ## v1.0.1 (patch) Changes since v1.0.0: - Update TextFilter library description ([@matt-edmondson](https://github.com/matt-edmondson)) ## v1.0.0 (major) - Initial commit ([@matt-edmondson](https://github.com/matt-edmondson)) - Additional documentation ([@matt-edmondson](https://github.com/matt-edmondson))

.NET 5.0

.NET Standard 2.1

.NET Standard 2.0

.NET 9.0

.NET 8.0

.NET 6.0

.NET 7.0

Version Downloads Last updated
1.5.5-pre.4 17 11/24/2025
1.5.5-pre.3 18 11/23/2025
1.5.5-pre.2 15 11/23/2025
1.5.5-pre.1 17 11/23/2025
1.5.4 20 08/26/2025