{"id":13805690,"url":"https://github.com/srackham/pcre2","last_synced_at":"2026-02-27T10:04:06.530Z","repository":{"id":141654725,"uuid":"545955618","full_name":"srackham/pcre2","owner":"srackham","description":"A V library for processing PCRE regular expressions","archived":false,"fork":false,"pushed_at":"2023-12-02T07:11:39.000Z","size":127,"stargazers_count":6,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-11T23:34:27.241Z","etag":null,"topics":["pcre2","regex","regular-expressions","vlang","vlang-module"],"latest_commit_sha":null,"homepage":"","language":"V","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/srackham.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":"2022-10-05T09:11:54.000Z","updated_at":"2025-01-07T12:22:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"f3119c25-cd06-4c39-a2fc-441ed7ff850d","html_url":"https://github.com/srackham/pcre2","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srackham%2Fpcre2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srackham%2Fpcre2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srackham%2Fpcre2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/srackham%2Fpcre2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/srackham","download_url":"https://codeload.github.com/srackham/pcre2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241347211,"owners_count":19948114,"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":["pcre2","regex","regular-expressions","vlang","vlang-module"],"created_at":"2024-08-04T01:01:03.880Z","updated_at":"2026-02-27T10:04:00.462Z","avatar_url":"https://github.com/srackham.png","language":"V","readme":"# pcre2\n\n**NOTE**: This release is graded alpha and is likely to experience API\nchanges up until the 1.0 release.\n## Overview\nA V library module for processing [Perl Compatible Regular Expressions (PCRE)](https://en.wikipedia.org/wiki/Perl_Compatible_Regular_Expressions) using the [PCRE2 library](https://www.pcre.org/).\n\n- The `pcre2` module is a wrapper for the PCRE2 8-bit runtime library.\n- Regex `find_*` methods search a `subject` string for regular expression matches.\n- Regex `replace_*` methods return a string in which matches in the `subject`\n  string are replaced by a replacement string or the result of a replacement function.\n- Regex `*_all_*` methods process all matches; `*_one_*` methods process the first match.\n- The Regex `replace_*_extended` methods support the PCRE2 extended replacements string syntax (see `PCRE2_SUBSTITUTE_EXTENDED` in the [pcre2api](https://www.pcre.org/current/doc/html/pcre2api.html) man page).\n- Currently there are no extraction methods for named subpatterns.\n- The [pcre module](https://github.com/vlang/pcre) (which uses the older PCRE library) was the inspiration and starting point for this project;\nthe [Go regex package](https://pkg.go.dev/regexp) also influenced the project.\n\n## Documentation\n- [pcre2 module documentation](https://srackham.github.io/pcre2/pcre2.html).\n- [PCRE regular expressions syntax](https://www.pcre.org/current/doc/html/pcre2syntax.html).\n- [Github repository](https://github.com/srackham/pcre2)\n\n## Examples\n```v\nimport srackham.pcre2\n\nfn main() {\n\t// Match words starting with `d` or `n`.\n\tr := pcre2.must_compile(r'\\b([dn].*?)\\b')\n\n\tsubject := 'Lorem nisi dis diam a cras placerat natoque'\n\n\t// Extract array of all matched strings.\n\ta := r.find_all(subject)\n\tprintln(a) // ['nisi', 'dis', 'diam', 'natoque']\n\n\t// Quote matched words.\n\ts1 := r.replace_all(subject, '\"$1\"')\n\tprintln(s1) // 'Lorem \"nisi\" \"dis\" \"diam\" a cras placerat \"natoque\"'\n\n\t// Replace all matched strings with upper case.\n\ts2 := r.replace_all_fn(subject, fn (m string) string {\n\t\treturn m.to_upper()\n\t})\n\tprintln(s2) // 'Lorem NISI DIS DIAM a cras placerat NATOQUE'\n\n\t// Replace all matched strings with upper case (PCRE2 extended replacement syntax).\n\ts3 := r.replace_all_extended(subject, r'\\U$1')\n\tprintln(s3) // 'Lorem NISI DIS DIAM a cras placerat NATOQUE'\n}\n```\nFor more examples see inside the [examples directory](https://github.com/srackham/pcre2/tree/master/examples) and take a look at the [module tests](https://github.com/srackham/pcre2/blob/master/pcre2_test.v).\n\n## Dependencies\nInstall the PCRE2 library:\n\n**Arch Linux and Manjaro**: `pacman -S pcre2`\n\n**Debian and Ubuntu**: `apt install libpcre2-dev`\n\n**Fedora**: `yum install pcre2-devel`\n\n**macOS**: `brew install pcre2`\n\n**Windows** †: `pacman.exe -S mingw-w64-x86_64-pcre2`\n\n† Uses the [MSYS2](https://www.msys2.org/) package management tools.\n\n## Installation\n\n    v install srackham.pcre2\n\nTest the installation by running:\n\n    v test $HOME/.vmodules/srackham/pcre2\n\nExample installation and test workflows for Ubuntu, macOS and Windows can be found in the Github Actions [workflow file](https://github.com/srackham/pcre2/blob/master/.github/workflows/ci.yml).\n\n## Performance\nComplex patterns can cause PCRE2 resource exhaustion. `find_*` library functions respond to such errors by raising a panic. The solution is to simplify the offending pattern.  Unlike, for example, the Go regexp package, PCRE2 does not have linear-time performance and while they may not trigger a panic, pathalogical patterns can exhibit slow performance. See the PCRE2 [pcre2perform man page](https://www.pcre.org/current/doc/html/pcre2perform.html).","funding_links":[],"categories":["Libraries"],"sub_categories":["Text processing"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsrackham%2Fpcre2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsrackham%2Fpcre2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsrackham%2Fpcre2/lists"}