package org.jkt.demo;
import org.apache.oro.text.regex.MalformedPatternException;
import org.apache.oro.text.regex.Pattern;
import org.apache.oro.text.regex.PatternCompiler;
import org.apache.oro.text.regex.PatternMatcher;
import org.apache.oro.text.regex.Perl5Compiler;
import org.apache.oro.text.regex.Perl5Matcher;
import org.apache.oro.text.regex.Perl5Substitution;
import org.apache.oro.text.regex.Util;
/**
* <a href="http://xxxx.com/interface.html#$1?param=2">
* @author micon
*
*/
public class ReplaceDemo {
public static void main(String[] args) throws MalformedPatternException {
// String rawStr = "2008-08-11 17:16:32";
// Perl5Matcher matcher = new Perl5Matcher();
// Pattern pattern = new Perl5Compiler().compile("(\\d{4})-(\\d{2})-(\\d{2}) (\\d{2}:\\d{2}:\\d{2})");
// String result = Util.substitute(matcher, pattern, new Perl5Substitution("变换 $3,$2,$1 $4"), rawStr, Util.SUBSTITUTE_ALL);
// System.out.println("格式yyyy-MM-dd HH:mm:ss到dd,MM,yyyy HH:mm:ss");
// System.out.println(result);
String link = "<a href=\"http://xxx.com/interface.html#how\">";
String regexpForLink = "<\\s*a\\s+href\\s*=\\s*\"http://xxx.com/interface.html#([^\"]+)\">";
PatternCompiler compiler = new Perl5Compiler();
Pattern pattertForLink = compiler.compile(regexpForLink,Perl5Compiler.CASE_INSENSITIVE_MASK);
PatternMatcher matcher = new Perl5Matcher();
String result = Util.substitute(matcher, pattertForLink,
new Perl5Substitution("<a href=\"http://newserver.com/interface.html#$1\">"),
link,
Util.SUBSTITUTE_ALL);
System.out.println(result);
}
}