import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 需求:获取指定字符串中由三个字符组成的单词
da jia ting wo shuo,jin tian yao xia yu,bu shang wan zi xi,gao xing bu?
*
*/
public class Test4 {
public static void main(String[] args) {
Pattern p = Pattern.compile("\\b[a-z]{3}\\b");
Matcher m = p.matcher("da jia ting wo shuo,jin tian yao xia yu,bu shang wan zi xi,gao xing bu");
while(m.find()){
System.out.println(m.group());
}
}
} |
|