zoukankan      html  css  js  c++  java
  • Java正则解析HTML一例

    import java.util.regex.Matcher;
    import java.util.regex.Pattern;


    public class Test {

    static String teststr = "UAPPROJECT_ID='402894cb4833decf014833e04fd70002 ; */' select ";

    /**
    * 包含回车换行符的处理
    */
    public static void testa(){
    Pattern wp = Pattern.compile("'.*?'", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
    Matcher m = wp.matcher(teststr);
    String result = m.replaceAll("");
    System.out.println("result:" + result);
    }

    /**
    * 包含回车换行符的处理
    */
    public static void testb(){
    String result = teststr.replaceAll("(?s)'.*?'", "");
    System.out.println("result:" + result);
    }

    public static void testc() {
    String a = "abc 您的查询码为:20160302175452496865,请妥善保存! def";
    String b = a.replaceAll("(?s).*您的查询码为:", "").replaceAll("(?s),请妥善保存!.*", "");
    System.out.println("result:" + b);
    }

    public static void main(String[] args) {
    testa();
    testb();
    testc();
    }
    }

  • 相关阅读:
    codevs 3657 括号序列
    洛谷P1962 斐波那契数列
    Black Rock shooter
    codevs 2596 售货员的难题
    51Nod-1154 回文串划分
    UVA
    POJ3321[苹果树] 树状数组/线段树 + dfs序
    Hdu 4578 Transformation (线段树 分类分析)
    786B
    438D
  • 原文地址:https://www.cnblogs.com/rgqancy/p/5237893.html
Copyright © 2011-2022 走看看