{"id":26234004,"url":"https://github.com/teragrep/jpr_01","last_synced_at":"2025-04-22T12:11:53.487Z","repository":{"id":118638660,"uuid":"573398144","full_name":"teragrep/jpr_01","owner":"teragrep","description":"Teragrep PCRE 2 Library for Java","archived":false,"fork":false,"pushed_at":"2024-07-23T06:13:13.000Z","size":209,"stargazers_count":6,"open_issues_count":11,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-29T15:02:15.524Z","etag":null,"topics":["java","java-lib","java-libraries","java-library","pcre","pcre-regex","pcre2","pcre2-libraries","pcre2-wrapper","regex","string-matching","teragrep"],"latest_commit_sha":null,"homepage":"https://teragrep.com","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/teragrep.png","metadata":{"files":{"readme":"README.adoc","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-12-02T11:18:59.000Z","updated_at":"2025-01-28T11:48:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"c0a6cc2f-1cc0-4e7e-9271-3b2673e713ed","html_url":"https://github.com/teragrep/jpr_01","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teragrep%2Fjpr_01","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teragrep%2Fjpr_01/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teragrep%2Fjpr_01/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/teragrep%2Fjpr_01/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/teragrep","download_url":"https://codeload.github.com/teragrep/jpr_01/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250237834,"owners_count":21397401,"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-lib","java-libraries","java-library","pcre","pcre-regex","pcre2","pcre2-libraries","pcre2-wrapper","regex","string-matching","teragrep"],"created_at":"2025-03-13T01:18:27.942Z","updated_at":"2025-04-22T12:11:53.469Z","avatar_url":"https://github.com/teragrep.png","language":"Java","readme":"= jpr_01\nThe jpr_01 library can be used to access PCRE2 Regex functionality from Java code. It uses Java Native Access to execute native C code for high performance and PCRE syntax compatibility compared to the native Java regex implementation.\n\nThe library can be used to retrieve the offsets of the input string that are matched against the given regular expression, and it can also retrieve multiple named groups within one matching operation. This information can be used for extracting information from the input string, or replacing parts of the input string.\n\n== Building\n\nTested on Fedora 36\n\n[,bash]\n----\ndnf install pcre2-devel\nmvn clean package\n----\n\n== Adding the library to your project\n\nTo use the library, it can be added via Maven:\n[,xml]\n----\n\u003cdependency\u003e\n      \u003cgroupId\u003ecom.teragrep\u003c/groupId\u003e\n      \u003cartifactId\u003ejpr_01\u003c/artifactId\u003e\n      \u003cversion\u003e3.0.1\u003c/version\u003e\n\u003c/dependency\u003e\n----\n\nAfter Maven has downloaded and setup the package, it can be imported and the JavaPcre object instantialized:\n\n[,java]\n----\nimport com.teragrep.jpr_01.JavaPcre;\n \nJavaPcre pcre = new JavaPcre();\n----\n\n== Pattern compilation\n\nThe regex matcher can be compiled for a given pattern using standard PCRE2 syntax\n\n[,java]\n----\nfinal String pattern = \"^Hello.*$\";\npcre.compile_java(pattern);\n----\n\nTo clear the compiled pattern, the jcompile_free() function can be used\n\n[,java]\n----\npcre.jcompile_free();\n----\n\n== Matching\n\nTo attempt matching the pattern, use the singlematch_java() function. The second argument specifies the offset, from which point of the String to start matching. To start from the beginning, use 0 (zero).\n\n[,java]\n----\nfinal String input = \"Hello this is a input\";\npcre.singlematch_java(input, 0);\n----\n\n== Extraction\n\nIf named capture groups are used, the results can be found via the match table and name table. The match table contains all the matches with unique IDs. Name table connects such unique IDs with any capture groups if given.\n\n[,java]\n----\nMap\u003cString, Integer\u003e nameTable = pcre.get_name_table(); // e.g. NameOfTeacher=1, NameOfAssistant=2\nMap\u003cInteger, String\u003e matchTable = pcre.get_match_table(); // e.g. 1=\"Anna\", 2=\"Robert\"\n----\n\nFor example, these maps can be used to get the groups and their contents mapped into one:\n\n[,java]\n----\nfinal Map\u003cString, String\u003e results = new HashMap\u003c\u003e();\nfor (final Map.Entry\u003cString, Integer\u003e me : nameTable.entrySet()) {\n    final String value = matchTable.get(me.getValue());\n    final String name = me.getKey();\n    results.put(name, value); // e.g. columnName=value\n}\n----\n\n== Match checking and location of matches\n\nTo check whether or not there is a match, the get_matchfound() function can be used.\n[,java]\n----\nboolean hasMatch = pcre.get_matchfound();\n----\n\nFor multiple matches, the get_matchfound() function can be used in conjunction with the singlematch_java()'s offset argument.\n\n[,java]\n----\nint offset = 0;\npcre.singlematch_java(inputStr, offset);\nwhile (pcre.get_matchfound()) {\n    offset = pcre.get_ovector1();\n    pcre.singlematch_java(inputStr, offset);\n}\n----\n\n== Offsets\n\nThe offsets (match starting index, match ending index) can be grabbed with the get_ovector0() and get_ovector1() functions.\n\n[,java]\n----\nint start = pcre.get_ovector0();\nint end = pcre.get_ovector1();\n----\n\n== Contributing\n \n// Change the repository name in the issues link to match with your project's name\n \nYou can involve yourself with our project by https://github.com/teragrep/jpr_01/issues/new/choose[opening an issue] or submitting a pull request.\n \nContribution requirements:\n \n. *All changes must be accompanied by a new or changed test.* If you think testing is not required in your pull request, include a sufficient explanation as why you think so.\n. Security checks must pass\n. Pull requests must align with the principles and http://www.extremeprogramming.org/values.html[values] of extreme programming.\n. Pull requests must follow the principles of Object Thinking and Elegant Objects (EO).\n \nRead more in our https://github.com/teragrep/teragrep/blob/main/contributing.adoc[Contributing Guideline].\n \n=== Contributor License Agreement\n \nContributors must sign https://github.com/teragrep/teragrep/blob/main/cla.adoc[Teragrep Contributor License Agreement] before a pull request is accepted to organization's repositories.\n \nYou need to submit the CLA only once. After submitting the CLA you can contribute to all Teragrep's repositories. \n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteragrep%2Fjpr_01","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fteragrep%2Fjpr_01","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fteragrep%2Fjpr_01/lists"}