<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ethan</title>
    <description>The latest articles on DEV Community by Ethan (@ethanzxlee).</description>
    <link>https://dev.to/ethanzxlee</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F112379%2Fa8da928b-c1f0-4529-ada6-5ffab1281614.gif</url>
      <title>DEV Community: Ethan</title>
      <link>https://dev.to/ethanzxlee</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ethanzxlee"/>
    <language>en</language>
    <item>
      <title>Repeated Capturing Group</title>
      <dc:creator>Ethan</dc:creator>
      <pubDate>Sat, 04 Apr 2020 00:00:00 +0000</pubDate>
      <link>https://dev.to/ethanzxlee/repeated-capturing-group-5f5e</link>
      <guid>https://dev.to/ethanzxlee/repeated-capturing-group-5f5e</guid>
      <description>&lt;p&gt;Regular expression can be used to check a string or a pattern is repeated in a string. For example, if you want to check if the string 'abc' is repeated for exactly 3 times in a string, you can use the following regex: &lt;code&gt;(abc)\1{2}&lt;/code&gt;, or it would be like this in Java after adding the escape characters:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="nc"&gt;Pattern&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="na"&gt;compile&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"(abc)\\1{2}"&lt;/span&gt;&lt;span class="o"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;\1&lt;/code&gt; in the regex matches the first capturing group in the regex. If you want it to match the second capturing group, you can use &lt;code&gt;\2&lt;/code&gt; and so on.&lt;/p&gt;

&lt;p&gt;It is also possible check if a capturing group is repeated at least &lt;code&gt;n&lt;/code&gt; times or more than &lt;code&gt;n&lt;/code&gt; times. For examples,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;to check if &lt;code&gt;abc&lt;/code&gt; is repeated in a string for at least 5 times, &lt;code&gt;(abc)\1{4,}&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;to check if &lt;code&gt;abc&lt;/code&gt; is repeated in a string for less than 5 times, &lt;code&gt;(abc)\1{0,4}&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>java</category>
      <category>regex</category>
      <category>code</category>
      <category>note</category>
    </item>
  </channel>
</rss>
