查找字符串的部分字符

Java旺

关注

阅读 76

2022-05-26

  //查找
public static void main2(String[] args) {
String str="Tomy-tomy-ToMy-tomyMan-tomyWoman";
Pattern pattern=Pattern.compile("Tomy",Pattern.CASE_INSENSITIVE);
Matcher matcher=pattern.matcher(str);

while(matcher.find()){
System.out.println(matcher.start());
System.out.println(matcher.end());
System.out.println(matcher.group());

System.out.println("----------------");

}


}


精彩评论(0)

0 0 举报