Thinking in Java. 正则表达式:检查一个句子或者字符串是否以大写字母开头,以句号结尾.

import java.util.Arrays;


public class Splitting{
public static String knights = 
"Then, when you have found the shrubbery, you must " + 
"cut down the mightiest tree in the forest.... " + 
"with.... a herring.";

/*public static void split(String regex)
{
if (regex.length() < 1)
{
System.out.printf("Not has regex");
System.exit(0);
}

System.out.println(Arrays.toString(knights.split(regex)));
}*/

public static void main(String[] args)
{
//正则表达式:检查一个句子或者字符串是否以大写字母开头,以句号结尾.
//^[A-Z].* 开头A-Z任意字符,^起始
//.*[\\.]$ 任意字符后有.结尾, $结尾
System.out.println(Splitting.knights.matches("^[A-Z].*[\\.]$"));
}
}

你可能感兴趣的:(Thinkin,in,Java,练习题)