用正则表达式匹配文章中所有的单词

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() + "]");
}

原文地址:https://www.cnblogs.com/jixu8/p/9408178.html