{"id":20480315,"url":"https://github.com/alexey-pelykh/pcre4j","last_synced_at":"2026-01-18T23:06:14.524Z","repository":{"id":245089664,"uuid":"817033023","full_name":"alexey-pelykh/pcre4j","owner":"alexey-pelykh","description":"PCRE for Java","archived":false,"fork":false,"pushed_at":"2025-01-09T19:39:14.000Z","size":236,"stargazers_count":6,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-09T20:29:55.619Z","etag":null,"topics":["java","java-library","pcre","pcre-regex","pcre2","pcre2-regex","pcre2-wrapper","regex","regexp"],"latest_commit_sha":null,"homepage":"https://pcre4j.org","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexey-pelykh.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":"2024-06-18T22:12:10.000Z","updated_at":"2025-01-09T19:39:16.000Z","dependencies_parsed_at":"2024-11-15T15:49:51.538Z","dependency_job_id":"7134046f-2795-4a40-beab-603b6866adef","html_url":"https://github.com/alexey-pelykh/pcre4j","commit_stats":null,"previous_names":["alexey-pelykh/pcre4j"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexey-pelykh%2Fpcre4j","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexey-pelykh%2Fpcre4j/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexey-pelykh%2Fpcre4j/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexey-pelykh%2Fpcre4j/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexey-pelykh","download_url":"https://codeload.github.com/alexey-pelykh/pcre4j/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234147904,"owners_count":18786934,"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":["java","java-library","pcre","pcre-regex","pcre2","pcre2-regex","pcre2-wrapper","regex","regexp"],"created_at":"2024-11-15T15:49:42.141Z","updated_at":"2026-01-18T23:06:14.517Z","avatar_url":"https://github.com/alexey-pelykh.png","language":"Java","funding_links":[],"categories":["解析库"],"sub_categories":["文件同步"],"readme":"# PCRE4J: PCRE for Java\n\n[![GitHub Repo stars](https://img.shields.io/github/stars/alexey-pelykh/pcre4j?style=flat\u0026logo=github)](https://github.com/alexey-pelykh/pcre4j)\n[![License](https://img.shields.io/github/license/alexey-pelykh/pcre4j)](https://www.gnu.org/licenses/lgpl-3.0.txt)\n[![CI](https://img.shields.io/github/check-runs/alexey-pelykh/pcre4j/main)](https://github.com/alexey-pelykh/pcre4j/actions/workflows/ci.yaml)\n[![codecov](https://codecov.io/gh/alexey-pelykh/pcre4j/graph/badge.svg?token=7UJZ501GWT)](https://codecov.io/gh/alexey-pelykh/pcre4j)\n[![Maven Central Version](https://img.shields.io/maven-central/v/org.pcre4j/lib)](https://mvnrepository.com/artifact/org.pcre4j/lib)\n[![javadoc](https://javadoc.io/badge2/org.pcre4j/lib/javadoc.svg)](https://javadoc.io/doc/org.pcre4j)\n\nThe PCRE4J project's goal is to bring the power of the [PCRE](https://www.pcre.org) library to Java.\n\nThis project is brought to you by [Alexey Pelykh](https://github.com/alexey-pelykh) with a great gratitude to the PCRE\nlibrary author [Philip Hazel](https://github.com/PhilipHazel) and its contributors.\n\nThe source code is hosted on [GitHub](https://github.com/alexey-pelykh/pcre4j).\n\n## Usage\n\nThe PCRE4J library provides several APIs to interact with the PCRE library:\n\n- `java.util.regex`-alike API via `org.pcre4j.regex.Pattern` and `org.pcre4j.regex.Matcher`\n- The PCRE4J API via `org.pcre4j.Pcre2Code` and related classes\n- The `libpcre2` direct API via backends that implement `org.pcre4j.api.IPcre2`\n\n### Quick Start with `java.util.regex`-alike API\n\nAdd the following dependencies to your `pom.xml` file:\n\n```xml\n\u003cdependencies\u003e\n    \u003cdependency\u003e\n        \u003cgroupId\u003eorg.pcre4j\u003c/groupId\u003e\n        \u003cartifactId\u003eregex\u003c/artifactId\u003e\n        \u003cversion\u003e0.4.4\u003c/version\u003e\n    \u003c/dependency\u003e\n    \u003cdependency\u003e\n        \u003cgroupId\u003eorg.pcre4j\u003c/groupId\u003e\n        \u003c!-- TODO: Select one of the following artifacts corresponding to the backend you want to use --\u003e\n        \u003cartifactId\u003ejna\u003c/artifactId\u003e\n        \u003c!-- \u003cartifactId\u003effm\u003c/artifactId\u003e --\u003e\n        \u003cversion\u003e0.4.4\u003c/version\u003e\n    \u003c/dependency\u003e\n\u003c/dependencies\u003e\n```\n\nProceed using the PCRE4J library in your Java code similarly like if you were using the `java.util.regex` package:\n\n```java\nimport org.pcre4j.Pcre4j;\n// TODO: Select one of the following imports for the backend you want to use:\nimport org.pcre4j.jna.Pcre2;\n// import org.pcre4j.ffm.Pcre2;\nimport org.pcre4j.regex.Pattern;\n\npublic class Usage {\n    static {\n        Pcre4j.setup(new Pcre2());\n    }\n\n    public static String[] example(String pattern, String subject) {\n        final var matcher = Pattern.compile(pattern).matcher(subject);\n        if (matcher.find()) {\n            final var groups = new String[matcher.groupCount() + 1];\n            for (var i = 0; i \u003c groups.length; i++) {\n                groups[i] = matcher.group(i);\n            }\n            return groups;\n        }\n        return null;\n    }\n}\n```\n\nBy default, the JIT compilation is used in cases the platform and the library support it. To override this behavior, you\ncan set the `pcre2.regex.jit` system property with the value `false` to the JVM.\n\n### Advanced Usage via PCRE4J API\n\nAdd the following dependencies to your `pom.xml` file:\n\n```xml\n\u003cdependencies\u003e\n    \u003cdependency\u003e\n        \u003cgroupId\u003eorg.pcre4j\u003c/groupId\u003e\n        \u003cartifactId\u003elib\u003c/artifactId\u003e\n        \u003cversion\u003e0.4.4\u003c/version\u003e\n    \u003c/dependency\u003e\n    \u003cdependency\u003e\n        \u003cgroupId\u003eorg.pcre4j\u003c/groupId\u003e\n        \u003c!-- TODO: Select one of the following artifacts corresponding to the backend you want to use --\u003e\n        \u003cartifactId\u003ejna\u003c/artifactId\u003e\n        \u003c!-- \u003cartifactId\u003effm\u003c/artifactId\u003e --\u003e\n        \u003cversion\u003e0.4.4\u003c/version\u003e\n    \u003c/dependency\u003e\n\u003c/dependencies\u003e\n```\n\nProceed using the PCRE4J library in your Java code:\n\n```java\nimport org.pcre4j.*;\n// TODO: Select one of the following imports for the backend you want to use:\nimport org.pcre4j.jna.Pcre2;\n// import org.pcre4j.ffm.Pcre2;\n\npublic class Usage {\n    static {\n        Pcre4j.setup(new Pcre2());\n    }\n\n    public static String[] example(String pattern, String subject) {\n        final Pcre2Code code;\n        if (Pcre4jUtils.isJitSupported(Pcre4j.api())) {\n            code = new Pcre2JitCode(\n                    pattern,\n                    EnumSet.noneOf(Pcre2CompileOption.class),\n                    null,\n                    null\n            );\n        } else {\n            code = new Pcre2Code(\n                    pattern,\n                    EnumSet.noneOf(Pcre2CompileOption.class),\n                    null\n            );\n        }\n        final var matchData = new Pcre2MatchData(code);\n        code.match(\n                subject,\n                0,\n                EnumSet.noneOf(Pcre2MatchOption.class),\n                matchData,\n                null\n        );\n        return Pcre4jUtils.getMatchGroups(code, subject, matchData);\n    }\n}\n```\n\n### Low-Level Usage\n\nAdd the following dependencies to your `pom.xml` file:\n\n```xml\n\u003cdependencies\u003e\n    \u003cdependency\u003e\n        \u003cgroupId\u003eorg.pcre4j\u003c/groupId\u003e\n        \u003c!-- TODO: Select one of the following artifacts corresponding to the backend you want to use --\u003e\n        \u003cartifactId\u003ejna\u003c/artifactId\u003e\n        \u003c!-- \u003cartifactId\u003effm\u003c/artifactId\u003e --\u003e\n        \u003cversion\u003e0.4.4\u003c/version\u003e\n    \u003c/dependency\u003e\n\u003c/dependencies\u003e\n```\n\nProceed using the `libpcre2` API in your Java code:\n\n```java\n// TODO: Select one of the following imports for the backend you want to use:\nimport org.pcre4j.jna.Pcre2;\n// import org.pcre4j.ffm.Pcre2;\n\npublic class Usage {\n    public static void example() {\n        final var pcre2 = new Pcre2();\n\n        final var errorcode = new int[1];\n        final var erroroffset = new long[1];\n        final var code = pcre2.compile(\"pattern\", 0, errorcode, erroroffset, 0);\n        if (code == 0) {\n            throw new RuntimeException(\n                    \"PCRE2 compilation failed with error code \" + errorcode[0] + \" at offset \" + erroroffset[0]\n            );\n        }\n\n        api.codeFree(code);\n    }\n}\n```\n\nSee the exposed PCRE2 API functions list [here](./PCRE2_API.md).\n\n## Backends\n\nThe PCRE4J library supports several backends to invoke the `pcre2` API.\n\n### `jna`\n\nThe `jna` backend uses the [Java Native Access](https://github.com/java-native-access/jna) library to invoke the `pcre2`\nshared library. For this backend to work, the `pcre2` shared library must be installed on the system and be visible via\n`jna.library.path`.\n\n### `ffm`\n\nThe `ffm` backend uses\nthe [Foreign Functions and Memory API](https://docs.oracle.com/en/java/javase/21/core/foreign-function-and-memory-api.html)\nto invoke the `pcre2` shared library. For this backend to work, the `pcre2` shared library must be installed on the\nsystem and be visible via `java.library.path`.\n\nNote that `--enable-preview` must be passed to the Java compiler to enable the preview features for this backend to be\nused.\n\n## Javadoc\n\nPlease see [the Javadoc Index](./javadoc/index.md) for the detailed API documentation.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexey-pelykh%2Fpcre4j","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexey-pelykh%2Fpcre4j","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexey-pelykh%2Fpcre4j/lists"}