Pattern pattern = Pattern.compile("(&|\\)(this is my target)=[^&]*");
我只想替换 this is my target 这一段,应该怎么办啊?

解决方案 »

  1.   

    http://www.exampledepot.com/egs/java.util.regex/GroupInRep.html// Compile regular expression 
    String patternStr = "\\((\\w+)\\)"; 
    String replaceStr = "<$1>"; 
    Pattern pattern = Pattern.compile(patternStr); 
    // Replace all (\w+) with <$1> 
    CharSequence inputStr = "a (b c) d (ef) g"; 
    Matcher matcher = pattern.matcher(inputStr); 
    String output = matcher.replaceAll(replaceStr); 
    // a (b c) d <ef> g 
      

  2.   

    只想替换 this is my target??
    那就用replaceAll函数啊。