zoukankan      html  css  js  c++  java
  • java正则表达式教程

    http://blog.csdn.net/yaerfeng/article/details/28855587

    例子

    package javastudy;
    
    public class Test3 {
    	static String s = "sdgjerj5346m456n45653m4";
    	
    	public static void main(String [] args){
    		String a = s.replaceAll("[^0-9]", "");
    		System.out.println(a);
    		
    		String str = "2006-04-06 02:31:04";
    		StringBuffer sb = new StringBuffer();
    		//\d正则表达式是非数字的意思以非数字分割字符串str,与[^0-9]等价
    		String [] result = str.split("\D");
    		for (int i=0;i<result.length;i++){
    			System.out.println(result[i]);
    			sb.append(result[i]);
    		}
    		System.out.println(sb.toString()) ;
    		
    		String b = str.replaceAll("[^0-9]", "");
    		System.out.println(b); 
    	}
    }
    

     结果为

    5346456456534
    2006
    04
    06
    02
    31
    04
    20060406023104
    20060406023104

     

  • 相关阅读:
    《我与我的父辈》影评
    如何进行时间规划?
    内向者相关
    修己 0815
    loj 3102
    StringSequences
    解方程
    problem B
    uoj424 count
    fft相关的复习
  • 原文地址:https://www.cnblogs.com/chuiyuan/p/4657523.html
Copyright © 2011-2022 走看看