{"id":31812677,"url":"https://github.com/stynh/flint","last_synced_at":"2026-05-16T17:38:53.848Z","repository":{"id":316612497,"uuid":"1063545419","full_name":"StynH/Flint","owner":"StynH","description":"A lightweight, zero-dependency library that provides fast text matching and replacement utilities.","archived":false,"fork":false,"pushed_at":"2025-10-03T16:19:34.000Z","size":129,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-03T18:35:42.758Z","etag":null,"topics":["c-sharp","dotnet","text-replacement","text-search"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/StynH.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-24T19:20:13.000Z","updated_at":"2025-10-03T16:19:37.000Z","dependencies_parsed_at":"2025-10-03T18:35:47.033Z","dependency_job_id":"170cce45-54ac-4d3a-a744-e2433f36056c","html_url":"https://github.com/StynH/Flint","commit_stats":null,"previous_names":["stynh/.net-flint","stynh/flint"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/StynH/Flint","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StynH%2FFlint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StynH%2FFlint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StynH%2FFlint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StynH%2FFlint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StynH","download_url":"https://codeload.github.com/StynH/Flint/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StynH%2FFlint/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279006602,"owners_count":26084130,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-sharp","dotnet","text-replacement","text-search"],"created_at":"2025-10-11T07:21:36.668Z","updated_at":"2025-10-11T07:21:41.363Z","avatar_url":"https://github.com/StynH.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"﻿# ![Icon](logo.png) \n![NuGet Version](https://img.shields.io/nuget/v/Flint) ![NuGet Downloads](https://img.shields.io/nuget/dt/Flint)\n\nFlint is a lightweight, zero-dependency C# library that provides fast text matching utilities using the [Aho-Corasick algorithm](https://en.wikipedia.org/wiki/Aho%E2%80%93Corasick_algorithm).\n\n## Usage Examples\n\n### Basic\n\n```csharp\nusing Flint;\n\nvar matcher = new TextMatcher(new[] { \"cat\", \"dog\" });\nvar results = matcher.Find(\"The dog chased the cat.\");\n\nforeach (var match in results)\n{\n    Console.WriteLine($\"Found '{match.Value}' at index {match.StartIndex}.\");\n}\n```\n\nOutput:\n\n```\nFound 'dog' at index 4.\nFound 'cat' at index 19.\n```\n\nAn optional ```StringComparison``` can be passed to ```TextMatcher```, influencing it's behavior when performing searches/replacement.\nIf none is given, it will default to ```StringComparison.CurrentCulture```.\n\n```csharp\nusing Flint;\n\nvar matcher = new TextMatcher(new[] { \"cat\", \"dog\" }, StringComparison.OrdinalIgnoreCase);\nvar results = matcher.Find(\"The DOG chased the CaT.\");\n\nforeach (var match in results)\n{\n    Console.WriteLine($\"Found '{match.Value}' at index {match.StartIndex}.\");\n}\n```\n\nOutput:\n\n```\nFound 'DOG' at index 4.\nFound 'CaT' at index 19.\n```\n\n### Find with a callback\n\n`TextMatcher` provides an overload of `Find` that accepts a callback invoked for each match. This can be convenient to process matches as they are found without allocating a results collection.\n\n```csharp\nusing Flint;\n\nvar matcher = new TextMatcher(new[] { \"cat\", \"dog\" });\nmatcher.Find(\"The dog chased the cat.\", match =\u003e\n{\n    Console.WriteLine($\"Found '{match.Value}' at index {match.StartIndex}.\");\n});\n```\n\nOutput:\n\n```\nFound 'dog' at index 4.\nFound 'cat' at index 19.\n```\n\n### Scan multiple texts with `FindAll`\n\n```csharp\nusing Flint;\n\nvar patterns = new[] { \"cat\", \"dog\", \"bird\" };\nvar matcher = new TextMatcher(patterns);\n\nvar texts = new[]\n{\n    \"The dog chased the cat.\",\n    \"A bird watched them from above.\",\n    \"No animals here.\"\n};\n\nvar all = matcher.FindAll(texts);\n\nforeach (var kv in all)\n{\n    Console.WriteLine(kv.Key);\n    foreach (var m in kv.Value)\n    {\n        Console.WriteLine($\"Found '{m.Value}' at index {m.StartIndex}.\");\n    }\n}\n```\n\nExample output:\n\n```\nThe dog chased the cat.\nFound 'cat' at index 19.\nFound 'dog' at index 4.\nA bird watched them from above.\nFound 'bird' at index 2.\nNo animals here.\n```\n\nIf you need to scan many input strings and handle matches as they are discovered, use the `FindAll` overload that accepts an `Action\u003cstring, Match\u003e` callback. The callback receives the original text and the match.\n\n```csharp\nusing Flint;\n\nvar patterns = new[] { \"cat\", \"dog\" };\nvar matcher = new TextMatcher(patterns);\n\nvar texts = new[]\n{\n    \"The dog chased the cat.\",\n    \"A bird watched from above.\",\n};\n\nmatcher.FindAll(texts, (text, match) =\u003e\n{\n    Console.WriteLine(text);\n    Console.WriteLine($\"Found '{match.Value}' at index {match.StartIndex}.\");\n});\n```\n\nExample output:\n\n```\nThe dog chased the cat.\nFound 'dog' at index 4.\nThe dog chased the cat.\nFound 'cat' at index 19.\nA bird watched from above.\n```\n\n### Exact (whole-word) matching with `MatchMode`\n\nThe `MatchMode` enum lets you require matches to be whole words. This prevents short patterns from matching inside longer words (for example, preventing \"he\" from matching inside \"she\").\n\n```csharp\nusing Flint;\n\nvar patterns = new[] { \"he\", \"she\" };\nvar matcher = new TextMatcher(patterns, StringComparison.CurrentCulture, MatchMode.ExactMatch);\n\nvar results = matcher.Find(\"she sells seashells.\");\n\nforeach (var m in results)\n{\n    Console.WriteLine($\"Found '{m.Value}' at index {m.StartIndex}.\");\n}\n```\n\nOutput (only the whole-word `she` is matched):\n\n```\nFound 'she' at index 0.\n```\n\n### Overlapping and nested matches\n\n```csharp\nusing Flint;\n\nvar matcher = new TextMatcher(new[] { \"he\", \"she\", \"his\", \"hers\" });\nvar results = matcher.Find(\"she is his hero\");\n\nforeach (var m in results)\n{\n    Console.WriteLine($\"Found '{m.Value}' at index {m.StartIndex}.\");\n}\n```\n\nExample output:\n\n```\nFound 'she' at index 0.\nFound 'he' at index 1.\nFound 'his' at index 7.\nFound 'he' at index 10.\n```\n\n### Replace all matches with a single value\n\n```csharp\nusing Flint;\n\nvar matcher = new TextMatcher(new[] { \"cat\", \"dog\" });\nvar replaced = matcher.Replace(\"The dog chased the cat.\", \"animal\");\nConsole.WriteLine(replaced);\n```\n\nOutput:\n\n```\nThe animal chased the animal.\n```\n\n### Replace matches using a function\n\n```csharp\nusing Flint;\n\nvar matcher = new TextMatcher(new[] { \"cat\", \"dog\" });\nvar replaced = matcher.Replace(\n    \"The dog chased the cat.\",\n    match =\u003e match.Value.ToUpper()\n);\nConsole.WriteLine(replaced);\n```\n\nOutput:\n\n```\nThe DOG chased the CAT.\n```\n\n### Replace each pattern with a different value\n\n```csharp\nusing Flint;\n\nvar matcher = new TextMatcher(new[] { \"cat\", \"dog\" });\nvar replaced = matcher.Replace(\n    \"The dog chased the cat.\",\n    new[] { \"feline\", \"canine\" }\n);\nConsole.WriteLine(replaced);\n```\n\nOutput:\n\n```\nThe canine chased the feline.\n```\n\n### Load patterns from a file\n\n```csharp\nusing Flint;\n\nvar patterns = File.ReadAllLines(\"patterns.txt\")\n                   .Where(l =\u003e !string.IsNullOrWhiteSpace(l));\n\nvar matcher = new TextMatcher(patterns);\n\nvar text = File.ReadAllText(\"large_input.txt\");\nvar hits = matcher.Find(text).ToArray();\n\nConsole.WriteLine($\"Found {hits.Length} matches.\");\n```\n\n## Support\n\n* .NET Standard 2.0 and .NET 8.0\n\n## License\n\nFlint is licensed under the [MIT License](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstynh%2Fflint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstynh%2Fflint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstynh%2Fflint/lists"}