title: Java : Regex expression for lastindexOf
body: <p>My sample code : </p>
  
  <pre><code>import java.util.regex.Matcher;
  import java.util.regex.Pattern;
  
  public class Test {
  
      /**
       * @param args
       */
  
      public static void main(String[] args) {
          // TODO Auto-generated method stub
  
          String str[] = {"A","B","C"};
          String s = "TEST FOR A STRING CONSTANT B. END.";
          int retIndex = -1;
  
          for (int i = 0, len = str.length; i &lt; len; i++){ 
              //length-1 is because, we should not check the empty space unicode(\u0021)
  
              int index = s.lastIndexOf(str[i]);
              if(index&gt;retIndex){
                  retIndex = index;
              }
          }
          System.out.println("RETINDEX"+retIndex);
  
          Pattern pattern = Pattern.compile("A|B|C");
          Matcher m = pattern.matcher(s);
  
          while(m.find()){
              retIndex = m.start();
              System.out.println(m.group()+" : "+m.end()+" : "+m.start());
          }
  
          System.out.println("REGEX RETINDEX"+retIndex);
      }
  }
  </code></pre>
  
  <p>And I got the output:</p>
  
  <pre><code>RETINDEX27
  A : 10 : 9
  C : 19 : 18
  A : 24 : 23
  B : 28 : 27
  REGEX RETINDEX27
  </code></pre>
  
  <p>I want the max index output only. No need to execute the other three loops. How to change the above one for my need?. Exactly lastindexOf match with regularExpression.</p>
  
  <p>Thanks</p>