{"id":20737215,"url":"https://github.com/aspiesoft/go-regex","last_synced_at":"2025-04-24T01:42:15.942Z","repository":{"id":49946923,"uuid":"498030314","full_name":"AspieSoft/go-regex","owner":"AspieSoft","description":"A High Performance PCRE Regex Package That Uses A Cache.","archived":false,"fork":false,"pushed_at":"2023-10-15T20:17:45.000Z","size":134,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-06T11:47:33.129Z","etag":null,"topics":["go","golang","pcre","pcre-regex","regex","regex-engine","regexp"],"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/AspieSoft.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-05-30T17:04:23.000Z","updated_at":"2024-04-26T21:19:51.000Z","dependencies_parsed_at":"2023-10-16T12:07:11.066Z","dependency_job_id":"b55699c3-a65c-43cd-b901-8a98e9f4cfd0","html_url":"https://github.com/AspieSoft/go-regex","commit_stats":{"total_commits":55,"total_committers":2,"mean_commits":27.5,"dds":"0.018181818181818188","last_synced_commit":"fbf711a1e5281a0e25762efe7145b7cd0e02f4c1"},"previous_names":[],"tags_count":40,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AspieSoft%2Fgo-regex","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AspieSoft%2Fgo-regex/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AspieSoft%2Fgo-regex/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AspieSoft%2Fgo-regex/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AspieSoft","download_url":"https://codeload.github.com/AspieSoft/go-regex/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250545691,"owners_count":21448247,"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":["go","golang","pcre","pcre-regex","regex","regex-engine","regexp"],"created_at":"2024-11-17T06:13:51.536Z","updated_at":"2025-04-24T01:42:15.922Z","avatar_url":"https://github.com/AspieSoft.png","language":"Go","funding_links":["https://paypal.me/shaynejrtaylor?country.x=US\u0026locale.x=en_US"],"categories":[],"sub_categories":[],"readme":"# Go Regex\n\n[![donation link](https://img.shields.io/badge/buy%20me%20a%20coffee-paypal-blue)](https://paypal.me/shaynejrtaylor?country.x=US\u0026locale.x=en_US)\n\nA High Performance PCRE Regex Package That Uses A Cache.\n\nSimplifies the the go-pcre regex package.\nAfter calling a regex, the compiled output gets cached to improve performance.\n\nThis package uses the [go-pcre](https://github.com/GRbit/go-pcre) package for better performance.\n\nIf you need better compatability, checkout my other RE2 based module [go-regex-re2](https://github.com/AspieSoft/go-regex-re2).\n\n## Installation\n\n```shell script\n  go get github.com/AspieSoft/go-regex/v8\n```\n\n## Dependencies\n\n### Debian/Ubuntu (Linux)\n\n```shell script\n  sudo apt install libpcre3-dev\n```\n\n### Fedora (Linux)\n\n```shell script\n  sudo dnf install pcre-devel\n```\n\n### Arch (Linux)\n\n```shell script\n  sudo yum install pcre-dev\n```\n\n## Usage\n\n```go\n\nimport (\n  \"github.com/AspieSoft/go-regex/v8\"\n\n  // or for verbose function names\n  \"github.com/AspieSoft/go-regex/v8/verbose\"\n)\n\n// this example will use verbose mode to make function names more clear\n\n// pre compile a regex into the cache\n// this method also returns the compiled pcre.Regexp struct\nregex.Compile(`re`)\n\n// compile a regex and safely escape user input\nregex.Compile(`re %1`, `this will be escaped .*`); // output: this will be escaped \\.\\*\nregex.Compile(`re %1`, `hello \\n world`); // output: hello \\\\n world (note: the \\ was escaped, and the n is literal)\ntree/v4.0.0\n// use %n to reference a param\n// use %{n} for param indexes with more than 1 digit\nregex.Compile(`re %1 and %2 ... %{12}`, `param 1`, `param 2` ..., `param 12`);\n\n// manually escape a string\n// note: the compile methods params are automatically escaped\nregex.Escape(`(.*)? \\$ \\\\$ \\\\\\$ regex hack failed`)\n\n// determine if a regex is valid, and can be compiled by this module\nregex.IsValid(`re`)\n\n// determine if a regex is valid, and can be compiled by the PCRE module\nregex.IsValidPCRE(`re`)\n\n// determine if a regex is valid, and can be compiled by the builtin RE2 module\nregex.IsValidRE2(`re`)\n\n// run a replace function (most advanced feature)\nregex.Compile(`(?flags)re(capture group)`).ReplaceFunc(myByteArray, func(data func(int) []byte) []byte {\n  data(0) // get the string\n  data(1) // get the first capture group\n\n  return []byte(\"\")\n\n  // if the last option is true, returning nil will stop the loop early\n  return nil\n}, true /* optional: if true, will not process a return output */)\n\n// run a replace function\nregex.Compile(`re (capture)`).ReplaceString(myByteArray, []byte(\"test $1\"))\n\n// run a simple light replace function\nregex.Compile(`re`).ReplaceStringLiteral(myByteArray, []byte(\"all capture groups ignored (ie: $1)\"))\n\n\n// return a bool if a regex matches a byte array\nregex.Compile(`re`).Match(myByteArray)\n\n// split a byte array in a similar way to JavaScript\nregex.Compile(`re|(keep this and split like in JavaScript)`).Split(myByteArray)\n\n// a regex string is modified before compiling, to add a few other features\n`use \\' in place of ` + \"`\" + ` to make things easier`\n`(?#This is a comment in regex)`\n\n// an alias of pcre.Regexp\nregex.PCRE\n\n// an alias of *regexp.Regexp\nregex.RE2\n\n// direct access to compiled pcre.Regexp\nregex.Compile(\"re\").RE\n\n\n// another helpful function\n// this method makes it easier to return results to a regex function\nregex.JoinBytes(\"string\", []byte(\"byte array\"), 10, 'c', data(2))\n\n// the above method can be used in place of this one\nappend(append(append(append([]byte(\"string\"), []byte(\"byte array\")...), []byte(strconv.Itoa(10))...), 'c'), data(2)...)\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faspiesoft%2Fgo-regex","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faspiesoft%2Fgo-regex","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faspiesoft%2Fgo-regex/lists"}