中国开发网: 论坛: 程序员情感CBD: 贴子 373356
品雪: 倒不完全是啦
import org.apache.oro.text.regex.MalformedPatternException;
import org.apache.oro.text.regex.MatchResult;
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;

public class Perl5RegExprHelper {

public static MatchResult ( String pattern, String str )
{
try{
PatternCompiler pc = new Perl5Compiler();
PatternMatcher pm = new Perl5Matcher();
Pattern pattern = pc.compile(pattern);
pm.contains(str, pattern);
return pm.getMatch();
}catch(Exception e){
return null;
}
}

public class Test{
public static void main(String[] args)
{
MatchResult r = Perl5RegExprHelper("([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})\\.([0-9]{1,3})","192.168.0.1");
System.out.println(mr.group(1)+" "+mr.group(2)+" "+mr.group(3)+" "+mr.group(4));
}
}

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录