1.在javascript中:

var str=‘int year = 2018;System.out.println(year + "不是闰年")';
str.match(/[a-zA-Z]+/ig);
//结果["int", "year", "System", "out", "println","year "]

2.在java中:

Pattern p = Pattern.compile("[a-zA-Z]+");
Matcher m = p.matcher(keywords[i].trim());
while (m.find()) {
    System.out.println(m.group() + "   位置:[" + m.start() + "," + m.end() + "]");
}

posted on 2018-08-02 16:55  jixu  阅读(2551)  评论(0编辑  收藏  举报