Here you can find the source of replaceTagsUnlessAnchorTagFound(String wikiString, String searchPattern, String replacementPattern)
private static String replaceTagsUnlessAnchorTagFound(String wikiString, String searchPattern, String replacementPattern)
//package com.java2s; import java.util.regex.Pattern; import java.util.regex.Matcher; public class Main { private static Pattern aPattern = null; private static Matcher aMatcher = null; private static String replaceTagsUnlessAnchorTagFound(String wikiString, String searchPattern, String replacementPattern) { boolean codeTagsFound = stringContainsPattern(wikiString, searchPattern); boolean hrefTagsFound = wikiString.contains("[["); // [[url][desc]] if (codeTagsFound && hrefTagsFound) { return wikiString; // don't modify the string, we'll just mess it up } else if (codeTagsFound) { aPattern = Pattern.compile(searchPattern); aMatcher = aPattern.matcher(wikiString); return aMatcher.replaceAll(replacementPattern); } else {//from www .j a va 2 s. c om return wikiString; } } private static boolean stringContainsPattern(String wikiString, String searchPattern) { Pattern p = Pattern.compile(searchPattern); Matcher m = p.matcher(wikiString); return m.find(); } }