import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class ZhengZe {
public static void main(String[] args) {
// TODO Auto-generated method stub
//使用正则表达式进行获取
String mail="xia wu ni yao wan you xin mang";
String regex="\\b\\w{3}\\b";
//把正则表达式变成正则对象
Pattern p=Pattern.compile(regex);
//将正则表达式与字符串相关连
Matcher matcher=p.matcher(mail);
while(matcher.find()){
int start= matcher.start();
int and=matcher.end();
String str=matcher.group();
System.out.println(start+"-----"+str+"-----"+and);
}
}
}
网友评论