ITeye博客

java中使用正则表达式

nowing · 2011-06-03 11:30 · 编程语言 · Markdown

使用apache的oro包 //匹配 'abc@jcc.inn' 2011/06/03 9:50

    String regrex = "'(*?+)*@(*?+)+{2,3}({2})?'\\s+\\d{4}/\\d{2}/\\d{2}\\s+\\d{1,2}:\\d{2}";

    compiler = new Perl5Compiler();
    pattern = null;
    try {
        pattern = compiler.compile(regrex);
    } catch (MalformedPatternException e) {
        logger.error(e);
        return;
    }
    matcher = new Perl5Matcher();
    String line = "       'abc@jcc.inn'  2011/06/03 9:50";
    if (matcher.contains(line, pattern)) {
        MatchResult result = matcher.getMatch();
        String findStr = result.group(0);
    }

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。