这是我的正则表达式,用于过滤一些常用词:
copyInputString.replaceAll("\\b(" +"http"+ ")\\b", " ");
如何替换“ http”替换单词列表?我的意思是将一个单词替换为单词列表以进行过滤。
怎么写代码?我试过了:
String commonWords = "http + haha + ...";
但这是行不通的。需要帮忙
将所有单词添加到列表中,然后像这样构建您的正则表达式:
List wordList = new ArrayList<String>();
// populate your wordList
// build the regex
String lstr = wordList.toString();
String regex = lstr.substring(1, lstr.length()-1).replace(", ", "|");
// replacement
String replaced = copyInputString.replaceAll("\\b(" + regex + ")\\b", " ");
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句