{"id":21823589,"url":"https://github.com/petere/pgpcre","last_synced_at":"2025-04-14T04:33:07.494Z","repository":{"id":6866368,"uuid":"8115298","full_name":"petere/pgpcre","owner":"petere","description":"PCRE functions for PostgreSQL","archived":false,"fork":false,"pushed_at":"2025-03-26T10:56:48.000Z","size":25,"stargazers_count":24,"open_issues_count":7,"forks_count":4,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-26T11:41:53.475Z","etag":null,"topics":["pcre","perl","postgresql","postgresql-extension","regular-expression"],"latest_commit_sha":null,"homepage":null,"language":"C","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/petere.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":"2013-02-09T21:20:22.000Z","updated_at":"2025-03-26T10:56:45.000Z","dependencies_parsed_at":"2024-11-27T17:43:46.478Z","dependency_job_id":null,"html_url":"https://github.com/petere/pgpcre","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petere%2Fpgpcre","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petere%2Fpgpcre/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petere%2Fpgpcre/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/petere%2Fpgpcre/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/petere","download_url":"https://codeload.github.com/petere/pgpcre/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248822107,"owners_count":21167002,"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":["pcre","perl","postgresql","postgresql-extension","regular-expression"],"created_at":"2024-11-27T17:33:41.057Z","updated_at":"2025-04-14T04:33:07.472Z","avatar_url":"https://github.com/petere.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# pgpcre\n\n[![Build Status](https://secure.travis-ci.org/petere/pgpcre.png)](http://travis-ci.org/petere/pgpcre)\n\nThis is a module for PostgreSQL that exposes Perl-compatible regular expressions (PCRE) functionality as functions and operators.  It is based on the popular [PCRE library](http://www.pcre.org/).\n\n## Installation\n\nYou need to have libpcre installed.  pkg-config will be used to find it.\n\nTo build and install this module:\n\n    make\n    make install\n\nor selecting a specific PostgreSQL installation:\n\n    make PG_CONFIG=/some/where/bin/pg_config\n    make PG_CONFIG=/some/where/bin/pg_config install\n\nAnd finally inside the database:\n\n    CREATE EXTENSION pgpcre;\n\n## Using\n\nA regular expression is a separate data type, named `pcre`.  (This is different from how the built-in regular expressions in PostgreSQL work, which are simply values of type `text`.)\n\nThe supported regular expressions are documented on the [pcrepattern(3)](http://linux.die.net/man/3/pcrepattern) man page.\n\n### Basic matching\n\nBoolean operators are available for checking whether a pattern matches a string.  These operators return true or false, respectively.  They only return null when one of the operands is null.\n\nExamples:\n\n    SELECT 'foo' ~ pcre 'fo+';\n    SELECT 'bar' !~ pcre 'fo+';\n\nYou can also write it the other way around:\n\n    SELECT pcre 'fo+' ~ 'foo';\n    SELECT pcre 'fo+' !~ 'bar';\n\nThis can be handy for writing things like\n\n    SELECT pcre 'fo+' ~ ANY(ARRAY['foo', 'bar']);\n\nFor Perl nostalgia, you can also use this operator:\n\n    SELECT 'foo' =~ pcre 'fo+';\n\nAnd if this operator is unique (which it should be, unless you have\nsomething else installed that uses it), you can also write:\n\n    SELECT 'foo' =~ 'fo+';\n\n(The `~` operator, by contrast, is not unique, of course, because it is used by the built-in regular expressions.)\n\nTo get case-insensitive matching, set the appropriate option in the pattern, for example:\n\n    SELECT 'FOO' ~ pcre '(?i)fo+';\n\n### Extracting the matched string\n\nTo extract the substring that was matched by the pattern, use the\nfunction `pcre_match`.  It returns either a value of type text, or\nnull if the pattern did not match.  Examples:\n\n    SELECT pcre_match('fo+', 'foobar');  --\u003e 'foo'\n    SELECT pcre_match('fo+', 'barbar');  --\u003e NULL\n\nThere is no support for extracting multiple matches of a pattern in a\nstring, because PCRE does not (easily) support that.\n\n### Extracting captured substrings\n\nCaptured substrings (parenthesized subexpressions) are extracted using\nthe function `pcre_captured_substrings`.  It returns either an array\nof text, or null if the pattern did not match.  Examples:\n\n    SELECT pcre_captured_substrings('(fo+)(b..)', 'foobar');  --\u003e ARRAY['foo','bar']\n    SELECT pcre_captured_substrings('(fo+)(b..)', 'abcdef');  --\u003e NULL\n\nNote that elements of the array can be null if a substring was not used, for example:\n\n    SELECT pcre_captured_substrings('(a|(z))(bc)', 'abc');  --\u003e ARRAY['a',NULL,'bc']\n\n### Storing regular expressions\n\nYou can store regular expression values of type `pcre` in tables, like\nany other data.  Note, however, that the binary representation of the\n`pcre` values contains the compiled regular expression, which is tied\nto the version of the PCRE library.  If you upgrade the PCRE library\nand use a compiled value created by a different version, things might\nnot work or even crash (according to the PCRE documentation; I don't\nknow how likely that is).  pgpcre will warn if you attempt to use a\nvalue that was compiled by a different version of the library.  If\nthat happens, it is advisable to recompile and rewrite all stored\n`pcre` values by doing something like\n\n    UPDATE ... SET pcre_col = pcre_col::text::pcre\n\n(To be clear, storing regular expressions in tables is not a typical\nuse.  Normally, you store text in tables and match it against regular\nexpressions provided by your application.)\n\n## Discussion\n\nSome possible advantages over the regular expression support built into PostgreSQL:\n\n- richer pattern language, more familiar to Perl and Python programmers\n- complete Unicode support\n- saner operators and functions\n\nSome disadvantages:\n\n- no repeated matching (`'g'` flag)\n- no index optimization\n\nYou can workaround the lack of index optimization by manually augmenting queries like\n\n    column =~ '^foo'\n\nwith\n\n    AND column ~\u003e=~ 'foo' AND column ~\u003c~ 'fop'\n\nand creating the appropriate `text_pattern_ops` index as you would for the built-in pattern matching.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpetere%2Fpgpcre","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpetere%2Fpgpcre","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpetere%2Fpgpcre/lists"}