Java Matcher requireEnd()

PreviousNext

java.util.regex.Matcher.requireEnd()

The java.util.regex.Matcher.requireEnd() method returns true if more input could change a positive match into a negative one.

Following is the declaration for java.util.regex.Matcher.requireEnd() method.

public boolean requireEnd()

Return Value

True if and only if more input could change a positive match into a negative one.

The following example shows the usage of java.util.regex.Matcher.requireEnd() method.

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
   private static String REGEX = "(a*b)(foo)";
   private static String INPUT = "abbfooabbfoo";
   private static String REPLACE = "-";
   /* w   ww    .d  e  m    o 2   s  . c o  m  */
   public static void main(String[] args) {
      Pattern pattern = Pattern.compile(REGEX);
      
      // get a matcher object
      Matcher matcher = pattern.matcher(INPUT);
      
      while(matcher.find()) {
         //Prints the offset after the last character matched.
         System.out.println("First Capturing Group, (a*b) Match String end(): "+matcher.end());   
         System.out.println("requireEnd(): "+matcher.requireEnd());    
      }     
   }
}

Result

PreviousNext

Related