{"id":1511,"date":"2021-12-07T20:23:37","date_gmt":"2021-12-07T07:23:37","guid":{"rendered":"https:\/\/www.ronella.xyz\/?p=1511"},"modified":"2021-12-07T20:23:37","modified_gmt":"2021-12-07T07:23:37","slug":"regex-capture-groups-with-java","status":"publish","type":"post","link":"https:\/\/www.ronella.xyz\/?p=1511","title":{"rendered":"Regex Capture Groups with Java"},"content":{"rendered":"<p>The following <strong>java code<\/strong> extracts the <strong>group<\/strong>, <strong>artifact<\/strong> and <strong>version<\/strong> using <strong>regex capture groups<\/strong>:<\/p>\n<pre><code class=\"language-java\">import java.util.regex.Pattern;\n\npublic class Main {\n\n    public static void main(String ... args) {\n        \/\/Text to extract the group, artifact and version\n        var text = &quot;org.junit.jupiter:junit-jupiter-api:5.7.0&quot;;\n\n        \/\/Regex capture groups for Group:Artifact:Version\n        var pattern = &quot;(.*):(.*):(.*)&quot;; \n\n        var compiledPattern = Pattern.compile(pattern);\n        var matcher = compiledPattern.matcher(text);\n        if (matcher.find( )) {\n            System.out.println(&quot;Whole text: &quot; + matcher.group(0) );\n            System.out.println(&quot;Group: &quot; + matcher.group(1) );\n            System.out.println(&quot;Artifact: &quot; + matcher.group(2) );\n            System.out.println(&quot;Version: &quot; + matcher.group(3) );\n        } else {\n            System.out.println(&quot;NO MATCH&quot;);\n        }\n    }\n}<\/code><\/pre>\n<p><strong>Output<\/strong><\/p>\n<pre><code>Whole text: org.junit.jupiter:junit-jupiter-api:5.7.0\nGroup: org.junit.jupiter\nArtifact: junit-jupiter-api\nVersion: 5.7.0<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>The following java code extracts the group, artifact and version using regex capture groups: import java.util.regex.Pattern; public class Main { public static void main(String &#8230; args) { \/\/Text to extract the group, artifact and version var text = &quot;org.junit.jupiter:junit-jupiter-api:5.7.0&quot;; \/\/Regex capture groups for Group:Artifact:Version var pattern = &quot;(.*):(.*):(.*)&quot;; var compiledPattern = Pattern.compile(pattern); var matcher = [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[47,60,30],"tags":[],"_links":{"self":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/1511"}],"collection":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1511"}],"version-history":[{"count":1,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/1511\/revisions"}],"predecessor-version":[{"id":1512,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/1511\/revisions\/1512"}],"wp:attachment":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1511"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}