MatchesTest.java
Dosyayı İndir
import java.util.regex.*;
public class MatchesTest {
public static void testMatchesShort(){
String regex=".*Godoro.*";
String input="Java Deeply by Godoro Publications";
boolean result=Pattern.matches(regex, input);
System.out.println("Matches : "+result);
}
public static void testMatchesLong(){
String regex=".*Godoro.*";
Pattern pattern=Pattern.compile(regex);
String input="Java Deeply by Godoro Publications";
Matcher matcher=pattern.matcher(input);
boolean result=matcher.matches();
System.out.println("Matches : "+result);
}
public static void testMatchesFlags(){
String regex=".*godoro.*";
Pattern pattern=Pattern.compile(regex,Pattern.CASE_INSENSITIVE);
String input="Java Deeply by Godoro Publications";
Matcher matcher=pattern.matcher(input);
boolean result=matcher.matches();
System.out.println("Matches : "+result);
}
public static void testBeginsMatches(){
String regex="^Java.*";
String input="Java Deeply by Godoro Publications";
boolean result=Pattern.matches(regex, input);
System.out.println("Matches : "+result);
}
public static void testEndsMatches(){
String regex=".*Publications$";
String input="Java Deeply by Godoro Publications";
boolean result=Pattern.matches(regex, input);
System.out.println("Matches : "+result);
}
public static void main(String[] args) {
testMatchesFlags();
}
}
Dosyayı İndir