title: Java String- How to get a part of package name in android?
body: <p>Its basically about getting string value between two characters. SO has many questions related to this. Like:</p>
  
  <p><a href="https://stackoverflow.com/questions/26897397/how-to-get-a-part-of-a-string-in-java">How to get a part of a string in java?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/12595019/how-to-get-a-string-between-two-characters">How to get a string between two characters?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/16597303/extract-string-between-two-strings-in-java">Extract string between two strings in java</a></p>
  
  <p>and more.
  But I felt it quiet confusing while dealing with multiple dots in the string and getting the value between certain two dots.</p>
  
  <p>I have got the package name as : </p>
  
  <pre><code>au.com.newline.myact
  </code></pre>
  
  <p>I need to get the value between "com." and the next "dot(.)". In this case "newline". I tried</p>
  
  <pre><code>Pattern pattern = Pattern.compile("com.(.*).");
  Matcher matcher = pattern.matcher(beforeTask);
  while (matcher.find()) {
          int ct = matcher.group();
  </code></pre>
  
  <p>I tried using substrings and IndexOf also. But couldn't get the intended answer. Because the package name in android varies by different number of dots and characters, I cannot use fixed index. Please suggest any idea.</p>