{"id":283,"date":"2018-04-24T08:26:54","date_gmt":"2018-04-23T20:26:54","guid":{"rendered":"https:\/\/content.ronella.xyz\/apps\/wordpress\/?p=283"},"modified":"2018-04-30T13:09:14","modified_gmt":"2018-04-30T01:09:14","slug":"regex-named-groups-with-sublime","status":"publish","type":"post","link":"https:\/\/www.ronella.xyz\/?p=283","title":{"rendered":"RegEx Named Groups with Sublime"},"content":{"rendered":"<p>Parentheses in regular expression (RegEx) can be used for grouping expression and can be named. To name it, after the opening parenthesis follows it with the following:<\/p>\n<pre> ?<em>&lt;name&gt;<\/em><\/pre>\n<p>Within the same expression you can backreference the group using the following:<\/p>\n<pre>\\k<em>&lt;name&gt;<\/em><\/pre>\n<p>On the <strong>replace field<\/strong>, based on the group position it will be numbered starting from 1 and increasing from the left of the expression and must be preceded with dollar sign <em>(i.e. $)<\/em>. Use this number to access the captured match.<\/p>\n<p><em>Note: if your group exceeds a single digit use <strong>${&lt;nn&gt;}<\/strong> (e.g. ${10}) notation.<\/em><\/p>\n<p>Example<\/p>\n<pre>&lt;?xml version=\"1.0\"?&gt;\r\n&lt;fruits&gt;\r\n &lt;a&gt;apple&lt;\/a&gt;\r\n &lt;b&gt;&lt;\/b&gt;\r\n &lt;c&gt;cashew&lt;\/c&gt;\r\n &lt;d&gt;&lt;\/d&gt;\r\n&lt;\/fruits&gt;<\/pre>\n<p>From the XML above find all the empty elements and add an attribute empty that is set to true.<\/p>\n<table style=\"height: 80px;\" width=\"645\">\n<tbody>\n<tr>\n<td width=\"45%\"><strong>Find<\/strong><\/td>\n<td width=\"35%\"><strong>Replace<\/strong><\/td>\n<td><strong>Comment<\/strong><\/td>\n<\/tr>\n<tr>\n<td>&lt;<strong><span style=\"color: #0000ff;\">(?&lt;tag&gt;\\w*[^&gt;])<\/span><\/strong>&gt;&lt;\/<span style=\"color: #008000;\"><strong>\\k&lt;tag&gt;<\/strong><\/span>&gt;<\/td>\n<td>&lt;$1 empty=\"true\"&gt;&lt;\/$1&gt;<\/td>\n<td>The named group <em>(i.e. blue text)<\/em> is assigned to $1.<\/p>\n<p>The \\k&lt;tag&gt; (i.e. green text) is the backreference.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>Parentheses in regular expression (RegEx) can be used for grouping expression and can be named. To name it, after the opening parenthesis follows it with the following: ?&lt;name&gt; Within the same expression you can backreference the group using the following: \\k&lt;name&gt; On the replace field, based on the group position it will be numbered starting [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[30,31],"tags":[],"_links":{"self":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/283"}],"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=283"}],"version-history":[{"count":9,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/283\/revisions"}],"predecessor-version":[{"id":326,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=\/wp\/v2\/posts\/283\/revisions\/326"}],"wp:attachment":[{"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ronella.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}