title: Regular expression to count <>
body: <p>So I've a case like this</p>
  
  <pre><code>&lt;&gt; = 1
  &lt;&gt;&lt;&gt; = 2
  &lt;&lt;&gt;&gt; = 2
  &lt;&lt;test&lt;&gt; = 1
  </code></pre>
  
  <p>How do I find all of the "&lt;>" it's inside the "&lt;>" as well using regular expression?</p>
  
  <p>Here's code that I've tried.</p>
  
  <pre><code>import java.io.IOException;
  import java.util.regex.*;
  import java.util.Scanner;
  
  public class Main {
      public static void main(String[] args) throws IOException {
          Scanner s = new Scanner(System.in);
          String input = s.nextLine();
  
          Pattern p = Pattern.compile("&lt;(.*?)&gt;");
          Matcher m = p.matcher(input);
  
          int count = 0;
          while(m.find()){
              count++;
          }
  
          System.out.println(count);
      }
  }
  </code></pre>