1.0测试表达式when in rome ,do as the romen.当中以ro开头的单词出现的次数
package 使用计数器;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
public class test1 {
public static void main(String[] args) {
String text="when in rome ,do as the romen."; //入乡随俗
String textSplit[]=text.split(" ");
Pattern myPattern= Pattern.compile("ro.+"); //匹配以ro开头的字符串
for (int i = 0; i < textSplit.length; i++) {
Matcher myMatcher =myPattern.matcher(textSplit[i]);
boolean boolean1=myMatcher.matches();
System.out.println(boolean1); //输出,匹配成功为true,否则为false
}
}
}