1.谁有关于正则代码的需求或者例子。发上就就行 有无答案均可。
2.例子要比较经典动脑,不要简单的例子。
3.最近正在学习正则 希望多做练习,要是例子有答案最好是java代码。其他均可。  希望能有更高回复。若是分不够可以继续加。~~~谢谢捧场~

解决方案 »

  1.   

    匹配IP地址,匹配文件路径,匹配URL,匹配log文件(格式自己找吧)...
      

  2.   


    /**
     * @Project <CL-Allocation tool>
     * @version <1.0>
     * @Author  <llddy>
     * @Date    <2008-9-22>
     * @description <取URL参数字符>
     */
    public class Test23 {
     public static void main(String[] args) {
        String str = "####PostList?modelclassID=3&deptID=5&current_page=1&page_rows=5&forum_id=45147####";
        Pattern p = Pattern.compile("####.*?\\?(.*?=.*?)&(.*?=.*?)&(.*?=.*?)&(.*?=.*?)&(.*?=.*?)####");
        Matcher m = p.matcher(str);
        while(m.find()) {
          for(int i=1;i<=5;i++) {
          System.out.println(m.group(i));
          }
        }
        System.out.println("OK");
      }
    }
      

  3.   

    将日期时间用正则转换并输出正确的日期格式。
    给你2个比较特别的时间
    03/2-3 03小时3:3
    "07/08/2009 3:33:23"运行结果 如下
    2003-2-3 3:03:03
    2009-7-8 3:33:23你研究下。
    代码在这里
    http://topic.csdn.net/u/20080925/11/9778d13e-e21e-4113-a76a-15d921ca69e2.html
      

  4.   


    /**
     * @Project <CL-Allocation tool>
     * @version <1.0>
     * @Author  <llddy>
     * @Date    <2008-9-23>
     * @description <匹配固定标签之间的URL>
     */
    public class Test30 {
      public static void main(String[] args){
      String[] str ={"<URL> http://www.goldhuman.com/newspaper/no-14/index1.htm </URL>",
             "<URL> http://www.goldhuman.com/newspaper/no-14/index2.htm </URL>",
             "<URL> http://www.goldhuman.com/newspaper/no-14/index3.htm </URL>",
             "<URL> http://www.goldhuman.com/newspaper/no-14/index4.htm </URL>"};
      Pattern p = Pattern.compile("<URL>(.*)</URL>");
      for (String string : str) {
      Matcher m = p.matcher(string);
      if(m.find()){
      System.out.println(m.group(1));
      }
          }
     
      }
    }
      

  5.   


    /**
     * @Project <CL-Allocation tool>
     * @version <1.0>
     * @Author  <llddy>
     * @Date    <2008-10-13>
     * @description 有两个有序整数集合a和b,写一个函数找出它们的交集? 
        火龙果@宝家族 代码
     */
    public class Test49 {
    public static void main(String args[]){
            int[] b = {4, 6, 7, 7, 7, 7, 8, 8, 9, 10, 100, 130, 130, 140, 150};
            int[] a = {2, 3, 4, 4, 4, 4, 7, 8, 8, 8, 8, 9, 100, 130, 150, 160};
            int[] c = intersect(a, b);
            System.out.println(Arrays.toString(c));
        }    public static int[] intersect(int[] a, int[] b) {
            if(a[0] > b[b.length - 1] || b[0] > a[a.length - 1]) {
                return new int[0];
            }
            int[] intersection = new int[Math.max(a.length, b.length)];
            int offset = 0;
            for(int i = 0, s = i; i < a.length && s < b.length; i++) {
                while(a[i] > b[s]) {
                    s++;
                }
                if(a[i] == b[s]) {
                    intersection[offset++] = b[s++];
                }
                while(i < (a.length - 1) && a[i] == a[i + 1]) {
                    i++;
                }
            }
            if(intersection.length == offset) {
                return intersection;
            }
            int[] duplicate = new int[offset];
            System.arraycopy(intersection, 0, duplicate, 0, offset);
            return duplicate;
        }}
      

  6.   


    /**
     * @Project <CL-Allocation tool>
     * @version <1.0>
     * @Author <llddy>
     * @Date <2008-9-18>
     * @description <正则表达式测试程序>
     */
    public class RegexTestHarness {
    public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);      
    while(true){
    System.out.printf("%n输入你的正则表达式: ");              
    Pattern pattern = Pattern.compile(scanner.nextLine());              
    System.out.printf("输入你要查找的字符串: ");              
    Matcher matcher = pattern.matcher(scanner.nextLine());             
    boolean found = false;             
    while (matcher.find()) {              
    System.out.printf(                       
    "I found the text \"%s\" starting at index %d and ending at index %d.%n",   
    matcher.group(), matcher.start(), matcher.end()                     
    );                  
    found = true;              }              
    if (!found) {                  
    System.out.printf("No match found.%n");              
    }          
    }      

    }
    }
      

  7.   


    /**
     * @Project <CL-Allocation tool>
     * @version <1.0>
     * @Author  <llddy>
     * @Date    <2008-9-17>
     * @description 
     */
    public class Test01 {
        public static void main(String[] args) {
            String[] strs = {
                    "",
                    "123",
                    "A4783",
                    "zA25$4783",
                    "z4uu3j57E{",
                    "524754x1&#",
                    "10248Zgk@",
                    "102xfas44dsfdhd48Zgk@",
                    "xfAs!dsf5dh&doo",
                    "xfAsmdsf5dhdoo"
                };        // 限定条件
             final String CONDITION = "(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)";        // 允许出现的字符
             final String SPECIAL_CHAR = "[-A-Za-z0-9!$%&()/;<?{}\\[\\]^\\\\]";        // 数量
             final String QUANTITY = "{8,16}";        Pattern pattern = Pattern.compile(CONDITION + SPECIAL_CHAR + QUANTITY);        for(String str : strs) {
                System.out.println(pattern.matcher(str).find());
            }
        }}
      

  8.   

    到这里下吧,http://www.verycd.com/topics/93279/
    这些视频我看了一大半了,就是好,没得说啊!!!!!
      

  9.   

    <a href="">匹配里面的网址(网络爬虫)