mediaSourceSpecificJunkCharacters=mediaSourceSpecificJunkCharacters+",";
Pattern p = Pattern.compile("\\[(.*?)\\],",Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
Matcher matcher = p.matcher(mediaSourceSpecificJunkCharacters);
while(matcher.find()) {
String stringToMatch=matcher.group(1);
System.out.println("string to match "+stringToMatch);
originalText=originalText.replaceAll(stringToMatch.trim(),"");
}
此处originalText="this is data from youtube youtube1 youtube2 youtube3 youtube4";
和mediaSourceSpecificJunkCharacters=[youtube2],[youtube3],[youtube4]
第一场比赛是youtube3而不是youtube2 ....所以youtube2永远不会被替换......为什么会这样?
答案 0 :(得分:1)
youtube1
中甚至没有mediaSourceSpecificJunkCharacters
。将其更改为
String mediaSourceSpecificJunkCharacters = "[youtube1],[youtube2],[youtube3],[youtube4]";
并将您的模式更改为
Pattern p = Pattern.compile("\\[(.*?)\\]", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
如果您也要替换youtube4
,最后的,
会阻止您的代码。