{"id":15061177,"url":"https://github.com/mmottl/pcre-ocaml","last_synced_at":"2025-10-29T14:03:20.708Z","repository":{"id":18361414,"uuid":"21541584","full_name":"mmottl/pcre-ocaml","owner":"mmottl","description":"OCaml bindings to PCRE (Perl Compatibility Regular Expressions)","archived":false,"fork":false,"pushed_at":"2025-02-18T21:01:17.000Z","size":1164,"stargazers_count":33,"open_issues_count":1,"forks_count":9,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-08T12:26:28.409Z","etag":null,"topics":["ocaml","pattern-matching","pcre","string-matching"],"latest_commit_sha":null,"homepage":null,"language":"OCaml","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mmottl.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":null,"funding":null,"license":"LICENSE.md","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":"2014-07-06T14:30:44.000Z","updated_at":"2025-02-18T20:58:53.000Z","dependencies_parsed_at":"2024-06-21T02:37:37.608Z","dependency_job_id":"b0c7d0fe-da21-4249-96ff-94aac8a99099","html_url":"https://github.com/mmottl/pcre-ocaml","commit_stats":{"total_commits":171,"total_committers":5,"mean_commits":34.2,"dds":0.0292397660818714,"last_synced_commit":"efdf4840f1a4d8e26f125fa9c18f2a02944e6897"},"previous_names":[],"tags_count":47,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmottl%2Fpcre-ocaml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmottl%2Fpcre-ocaml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmottl%2Fpcre-ocaml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmottl%2Fpcre-ocaml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mmottl","download_url":"https://codeload.github.com/mmottl/pcre-ocaml/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmottl%2Fpcre-ocaml/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259184740,"owners_count":22818267,"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":["ocaml","pattern-matching","pcre","string-matching"],"created_at":"2024-09-24T23:11:04.370Z","updated_at":"2025-06-11T02:06:47.940Z","avatar_url":"https://github.com/mmottl.png","language":"OCaml","funding_links":[],"categories":["Regular Expressions"],"sub_categories":[],"readme":"# PCRE-OCaml - Perl Compatibility Regular Expressions for OCaml\n\nThis [OCaml](http://www.ocaml.org) library interfaces with the C library\n[PCRE](http://www.pcre.org), providing Perl-compatible regular expressions\nfor string matching.\n\n## Features\n\nPCRE-OCaml offers:\n\n- Pattern searching\n- Subpattern extraction\n- String splitting by patterns\n- Pattern substitution\n\nReasons to choose PCRE-OCaml:\n\n- The PCRE library by Philip Hazel is mature and stable, implementing nearly\n  all Perl regular expression features. High-level OCaml functions (split,\n  replace, etc.) are compatible with Perl functions, as much as OCaml allows.\n  Some developers find Perl-style regex syntax more intuitive and powerful\n  than the Emacs-style regex used in OCaml's `Str` module.\n\n- PCRE-OCaml is reentrant and thread-safe, unlike the `Str` module. This\n  reentrancy offers convenience, eliminating concerns about library state.\n\n- High-level replacement and substitution functions in OCaml are faster than\n  those in the `Str` module. When compiled to native code, they can even\n  outperform Perl's C-based functions.\n\n- Returned data is unique, allowing safe destructive updates without side\n  effects.\n\n- The library interface uses labels and default arguments for enhanced\n  programming comfort.\n\n## Usage\n\nPlease run:\n\n```sh\nodig odoc pcre2\n```\n\nOr:\n\n```sh\ndune build @doc\n```\n\nConsult the [API](https://mmottl.github.io/pcre-ocaml/api/pcre) for details.\n\nFunctions support two flag types:\n\n1. **Convenience flags**: Readable and concise, translated internally on each\n   call. Example:\n\n   ```ocaml\n   let rex = Pcre.regexp ~flags:[`ANCHORED; `CASELESS] \"some pattern\" in\n   (* ... *)\n   ```\n\n   These are easy to use but may incur overhead in loops. For performance\n   optimization, consider the next approach.\n\n2. **Internal flags**: Predefined and translated from convenience flags for\n   optimal loop performance. Example:\n\n   ```ocaml\n   let iflags = Pcre.cflags [`ANCHORED; `CASELESS] in\n   for i = 1 to 1000 do\n     let rex = Pcre.regexp ~iflags \"some pattern constructed at runtime\" in\n     (* ... *)\n   done\n   ```\n\n   Translating flags outside loops saves cycles. Avoid creating regex in\n   loops:\n\n   ```ocaml\n   for i = 1 to 1000 do\n     let chunks = Pcre.split ~pat:\"[ \\t]+\" \"foo bar\" in\n     (* ... *)\n   done\n   ```\n\n   Instead, predefine the regex:\n\n   ```ocaml\n   let rex = Pcre.regexp \"[ \\t]+\" in\n   for i = 1 to 1000 do\n     let chunks = Pcre.split ~rex \"foo bar\" in\n     (* ... *)\n   done\n   ```\n\nFunctions use optional arguments with intuitive defaults. For instance,\n`Pcre.split` defaults to whitespace as the pattern. The `examples` directory\ncontains applications demonstrating PCRE-OCaml's functionality.\n\n## Restartable (Partial) Pattern Matching\n\nPCRE includes a DFA match function for restarting partial matches with new\ninput, exposed via `pcre_dfa_exec`. While not suitable for extracting\nsubmatches or splitting strings, it's useful for streaming and search tasks.\n\nExample of a partial match restarted:\n\n```ocaml\nutop # open Pcre;;\nutop # let rex = regexp \"12+3\";;\nval rex : regexp = \u003cabstr\u003e\nutop # let workspace = Array.make 40 0;;\nval workspace : int array =\n  [| ... |]\nutop # pcre_dfa_exec ~rex ~flags:[`PARTIAL] ~workspace \"12222\";;\nException: Pcre.Error Partial.\nutop # pcre_dfa_exec ~rex ~flags:[`PARTIAL; `DFA_RESTART] ~workspace \"2222222\";;\nException: Pcre.Error Partial.\nutop # pcre_dfa_exec ~rex ~flags:[`PARTIAL; `DFA_RESTART] ~workspace \"2222222\";;\nException: Pcre.Error Partial.\nutop # pcre_dfa_exec ~rex ~flags:[`PARTIAL; `DFA_RESTART] ~workspace \"223xxxx\";;\n- : int array = [|0; 3; 0|]\n```\n\nRefer to the `pcre_dfa_exec` documentation and the `dfa_restart` example for\nmore information.\n\n## Contact Information and Contributing\n\nSubmit bug reports, feature requests, and contributions via the\n[GitHub issue tracker](https://github.com/mmottl/pcre-ocaml/issues).\n\nFor the latest information, visit: \u003chttps://mmottl.github.io/pcre-ocaml\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmmottl%2Fpcre-ocaml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmmottl%2Fpcre-ocaml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmmottl%2Fpcre-ocaml/lists"}