{"id":23408574,"url":"https://github.com/toqueteos/substring","last_synced_at":"2025-06-24T08:03:11.996Z","repository":{"id":33542210,"uuid":"37188342","full_name":"toqueteos/substring","owner":"toqueteos","description":":zap: Very fast one-time string searches in Go. Simple and composable.","archived":false,"fork":false,"pushed_at":"2020-01-10T17:55:28.000Z","size":13,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"v2","last_synced_at":"2025-04-11T23:53:02.861Z","etag":null,"topics":["compare","go","search","speed","string"],"latest_commit_sha":null,"homepage":"https://pkg.go.dev/github.com/toqueteos/substring","language":"Go","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/toqueteos.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}},"created_at":"2015-06-10T09:38:15.000Z","updated_at":"2023-12-05T11:04:39.000Z","dependencies_parsed_at":"2022-08-07T22:00:40.294Z","dependency_job_id":null,"html_url":"https://github.com/toqueteos/substring","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/toqueteos/substring","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toqueteos%2Fsubstring","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toqueteos%2Fsubstring/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toqueteos%2Fsubstring/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toqueteos%2Fsubstring/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/toqueteos","download_url":"https://codeload.github.com/toqueteos/substring/tar.gz/refs/heads/v2","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/toqueteos%2Fsubstring/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261632034,"owners_count":23187268,"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","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":["compare","go","search","speed","string"],"created_at":"2024-12-22T15:15:51.131Z","updated_at":"2025-06-24T08:03:11.973Z","avatar_url":"https://github.com/toqueteos.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# substring [![Build Status](https://travis-ci.org/toqueteos/substring.png?branch=master)](https://travis-ci.org/toqueteos/substring) [![GoDoc](http://godoc.org/github.com/toqueteos/substring?status.png)](http://godoc.org/github.com/toqueteos/substring)\n\nVery fast **one-time string searches** in Go. Simple and composable.\n\nInterop with [regexp](http://golang.org/pkg/regexp/) for backwards compatibility (easy migration from your current system to `substring`).\n\n## Installation\n\nThe recommended way to install substring is by using `go get`:\n\n```\ngo get github.com/toqueteos/substring\n```\n\nGo Modules are supported!\n\n## Examples\n\nA basic example with two matchers:\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"regexp\"\n\n\t\"github.com/toqueteos/substring/v2\"\n)\n\nfunc main() {\n\tm1 := substring.After(\"assets/\", substring.Or(\n\t\tsubstring.Has(\"jquery\"),\n\t\tsubstring.Has(\"angular\"),\n\t\tsubstring.Suffixes(\".js\", \".css\", \".html\"),\n\t))\n\tfmt.Println(m1.Match(\"assets/angular/foo/bar\")) // Prints: true\n\tfmt.Println(m1.Match(\"assets/js/file.js\"))      // Prints: true\n\tfmt.Println(m1.Match(\"assets/style/bar.css\"))   // Prints: true\n\tfmt.Println(m1.Match(\"assets/foo/bar.html\"))    // Prints: true\n\tfmt.Println(m1.Match(\"assets/js/qux.json\"))     // Prints: false\n\tfmt.Println(m1.Match(\"core/file.html\"))         // Prints: false\n\tfmt.Println(m1.Match(\"foobar/that.jsx\"))        // Prints: false\n\tfmt.Println()\n\n\tm2 := substring.After(\"vendor/\", substring.Suffixes(\".css\", \".js\", \".less\"))\n\tfmt.Println(m2.Match(\"foo/vendor/bar/qux.css\")) // Prints: true\n\tfmt.Println(m2.Match(\"foo/var/qux.less\"))       // Prints: false\n\tfmt.Println()\n\n\tre := regexp.MustCompile(`vendor\\/.*\\.(css|js|less)$`)\n\tfmt.Println(re.MatchString(\"foo/vendor/bar/qux.css\")) // Prints: true\n\tfmt.Println(re.MatchString(\"foo/var/qux.less\"))       // Prints: false\n}\n```\n\n## How fast?\n\nIt may vary depending on your use case but 1~2 orders of magnitude faster than `regexp` is pretty common.\n\nTest it out for yourself by running `go test -bench .`!\n\n```\n$ go test -bench .\npkg: github.com/toqueteos/substring\nBenchmarkExample1-16            30759529                38.4 ns/op\nBenchmarkExample2-16            26659675                40.0 ns/op\nBenchmarkExample3-16            30760317                37.7 ns/op\nBenchmarkExample4-16            31566652                36.8 ns/op\nBenchmarkExample5-16           123704845                9.70 ns/op\nBenchmarkExampleRe1-16           2739574                 436 ns/op\nBenchmarkExampleRe2-16           2494791                 480 ns/op\nBenchmarkExampleRe3-16           1681654                 713 ns/op\nBenchmarkExampleRe4-16           2205490                 540 ns/op\nBenchmarkExampleRe5-16          19673001                55.0 ns/op\nPASS\nok      github.com/toqueteos/substring  15.016s\n```\n\n## License\n\nMIT, see [LICENSE](LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoqueteos%2Fsubstring","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftoqueteos%2Fsubstring","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftoqueteos%2Fsubstring/lists"}