{"id":34090084,"url":"https://github.com/mmkhattab/multimatcher","last_synced_at":"2026-04-09T04:32:11.499Z","repository":{"id":156646682,"uuid":"632153173","full_name":"mmkhattab/multimatcher","owner":"mmkhattab","description":"A convenient implementation of the Aho-Corasick algorithm to find multiple search patterns","archived":false,"fork":false,"pushed_at":"2023-11-04T21:01:28.000Z","size":28,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-03T06:59:41.392Z","etag":null,"topics":["aho-corasick","string-search"],"latest_commit_sha":null,"homepage":"","language":"Python","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/mmkhattab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-04-24T20:26:48.000Z","updated_at":"2023-09-20T21:36:01.000Z","dependencies_parsed_at":"2023-09-20T22:09:44.823Z","dependency_job_id":null,"html_url":"https://github.com/mmkhattab/multimatcher","commit_stats":null,"previous_names":["mmkhattab/multimatcher"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/mmkhattab/multimatcher","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmkhattab%2Fmultimatcher","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmkhattab%2Fmultimatcher/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmkhattab%2Fmultimatcher/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmkhattab%2Fmultimatcher/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mmkhattab","download_url":"https://codeload.github.com/mmkhattab/multimatcher/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmkhattab%2Fmultimatcher/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31586403,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"online","status_checked_at":"2026-04-09T02:00:06.848Z","response_time":112,"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":["aho-corasick","string-search"],"created_at":"2025-12-14T14:10:18.266Z","updated_at":"2026-04-09T04:32:11.492Z","avatar_url":"https://github.com/mmkhattab.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Introduction\nMultimatcher is an implementation of the Aho-Corasick (Aho \u0026 Corasick 1975) search algorithm.\nIt efficiently finds multiple keywords in an input string, without having to loop\nover the input string multiple times.\n\nThe rationale behind the Multimatcher is that most often we want to do something with the found matches, and\nthe Multimatcher provides a flexible \"replace\" method that allows different use cases such as:\n\n- find and delete\n- find and replace\n- tag with a global label (i.e. all matches get the same label)\n- tag with custom label (i.e. each match gets its own label)\n- count matches\n\nWhen possible, it's recommended to set whole_words_only to True, which makes matching significantly faster.\n\n# Examples\n## Find and delete matches\n```\nfrom multimatcher import Multimatcher\nmm = Multimatcher(separator=' ')\nmm.set_replacement_text(\"\") # matches will be deleted\nmm.set_search_patterns(['a', 'b', 'c'])\nmm.replace(\"x a y b z c\") # produces \"x y z\"\n```\n## Find and transform matches\n```\nfrom multimatcher import Multimatcher\nmm = Multimatcher(separator=' ')\nmm.set_replacement_method(lambda x: x.capitalize()) # matches will be capitalized\nmm.set_search_patterns(['a', 'b', 'c'])\nmm.replace(\"x a y b z c\") # produces \"x A y B z C\"\n```\n## Find and replace matches with the same label\n```\nfrom multimatcher import Multimatcher\nmm = Multimatcher(separator=' ')\nmm.set_replacement_text(\"0\") # all matches will be replaced with 0\nmm.set_search_patterns(['a', 'b', 'c'])\nmm.replace(\"x a y b z c\") # produces \"x 0 y 0 z 0\"\n```\n## Find and replace matches with custom labels\n```\nfrom multimatcher import Multimatcher\nmm = Multimatcher(separator=' ')\nmm.set_replacement_map({\"a\": \"1\", \"b\": \"2\", \"c\": \"3\"}) # replaces a \u003e 1, b \u003e 2, c \u003e 3\nmm.set_search_patterns(['a', 'b', 'c'])\nmm.replace(\"x a y b z c\") # produces \"x 1 y 2 z 3\"\n```\n\n## Find and replace matches with custom labels\n```\nfrom multimatcher import Multimatcher\nmm = Multimatcher(separator='')\nmm.set_search_patterns(['a', 'b', 'c'])\nmm.count(\"aa xx bb yy cc zz\") # produces {'a': 2, 'b': 2, 'c': 2}\n```\n# References\nAho, A. V., \u0026 Corasick, M. J. (1975). Efficient string matching: an aid to bibliographic search.\nCommunications of the ACM, 18(6), 333-340.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmmkhattab%2Fmultimatcher","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmmkhattab%2Fmultimatcher","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmmkhattab%2Fmultimatcher/lists"}