{"id":15557472,"url":"https://github.com/icholy/replace","last_synced_at":"2025-08-17T13:32:15.818Z","repository":{"id":57533400,"uuid":"280246067","full_name":"icholy/replace","owner":"icholy","description":"Streaming text replacement for Go","archived":false,"fork":false,"pushed_at":"2022-09-07T17:42:35.000Z","size":63,"stargazers_count":71,"open_issues_count":1,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-17T06:26:07.032Z","etag":null,"topics":["go","golang","replace-text"],"latest_commit_sha":null,"homepage":"","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/icholy.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":"2020-07-16T19:57:25.000Z","updated_at":"2025-02-11T09:08:02.000Z","dependencies_parsed_at":"2022-09-26T18:21:04.619Z","dependency_job_id":null,"html_url":"https://github.com/icholy/replace","commit_stats":null,"previous_names":["icholy/replacer"],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/icholy/replace","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icholy%2Freplace","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icholy%2Freplace/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icholy%2Freplace/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icholy%2Freplace/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/icholy","download_url":"https://codeload.github.com/icholy/replace/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icholy%2Freplace/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270856561,"owners_count":24657688,"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-08-17T02:00:09.016Z","response_time":129,"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":["go","golang","replace-text"],"created_at":"2024-10-02T15:18:04.278Z","updated_at":"2025-08-17T13:32:15.510Z","avatar_url":"https://github.com/icholy.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Streaming text replacement\n\n[![GoDoc](https://godoc.org/github.com/icholy/replace?status.svg)](https://godoc.org/github.com/icholy/replace)\n\n\u003e This package provides a [x/text/transform.Transformer](https://godoc.org/golang.org/x/text/transform#Transformer)\n\u003e implementation that replaces text\n\n## Example\n\n``` go\npackage main\n\nimport (\n\t\"io\"\n\t\"os\"\n\t\"regexp\"\n\n\t\"github.com/icholy/replace\"\n)\n\nfunc main() {\n\tf, _ := os.Open(\"file\")\n\tdefer f.Close()\n\n\tr := replace.Chain(f,\n\t\t// simple replace\n\t\treplace.String(\"foo\", \"bar\"),\n\t\treplace.Bytes([]byte(\"thing\"), []byte(\"test\")),\n\n\t\t// remove all words that start with baz\n\t\treplace.Regexp(regexp.MustCompile(`baz\\w*`), nil),\n\n\t\t// surround all words with parentheses\n\t\treplace.RegexpString(regexp.MustCompile(`\\w+`), \"($0)\"),\n\n\t\t// increment all numbers\n\t\treplace.RegexpStringFunc(regexp.MustCompile(`\\d+`), func(match string) string {\n\t\t\tx, _ := strconv.Atoi(match)\n\t\t\treturn strconv.Itoa(x+1)\n\t\t}),\n\t)\n\n\t_, _ = io.Copy(os.Stdout, r)\n}\n```\n\n## Notes Regexp* functions\n\n* `RegexpTransformer` is stateful and cannot be used concurrently.\n* The `replace` functions should not save or modify any `[]byte` parameters they recieve.\n* If a match is longer than `MaxMatchSize` it may be skipped (Default 2kb).\n* For better performance, reduce the `MaxMatchSize` size to the largest possible match.\n* Do not use with [transform.Chain](https://pkg.go.dev/golang.org/x/text/transform#Chain), see https://github.com/golang/go/issues/49117.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficholy%2Freplace","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ficholy%2Freplace","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficholy%2Freplace/lists"}