public void findText(List<String> textList, List<String> labelList) { if (null == textList || textList.size() == 0 || null == labelList || labelList.size() == 0) { return; } // 目标标签 Set<String> labelSet = new HashSet<>(64); String targetText, labelText; int index, lastIndex, textLength; boolean legal = true; for (String text : textList) { targetText = text; while (StringUtils.isNoneBlank(targetText) && -1 != (index = targetText.indexOf("#{")) && -1 != (lastIndex = targetText.indexOf("}"))) { // 避免出现类似于“}}}text#{”的情况出现 while (lastIndex < index) { targetText = targetText.substring(lastIndex + 1); index = targetText.indexOf("#{"); lastIndex = targetText.indexOf("}"); if (-1 == lastIndex) { legal = false; break; } } if (!legal) { break; } labelText = targetText.substring(index + 2, lastIndex); // 解决“#{{{{#{labelName}}”读到 {{{#{labelName 的情况 while (-1 != (index = labelText.indexOf("#{")) && index < lastIndex) { labelText = labelText.substring(index + 2); } labelSet.add(labelText.trim()); textLength = targetText.length(); if ((lastIndex + 1) < textLength) { targetText = targetText.substring(lastIndex + 1); } else { break; } } } // 将从文本中读到的labelSet集合中的标签,筛选出符合labelList中的目标标签 }