package com.ssj.kmt.utils;

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

public class RegexUtil {

	
	  /** 
     * 正则表达式匹配两个指定字符串中间的内容 
     * @param soap 
     * @return 
     */  
    public static List<String> getSubUtil(String soap,String rgex){  
        List<String> list = new ArrayList<String>();  
        Pattern pattern = Pattern.compile(rgex);// 匹配的模式  
        Matcher m = pattern.matcher(soap);  
        while (m.find()) {  
            int i = 1;  
            list.add(m.group(i));  
            i++;  
        }  
        return list;  
    }  
    
    
    /** 
     * 正则表达式匹配两个指定字符串中间的内容 
     * @param soap 
     * @return 
     */  
    public static List<String> getSub(String str,String rgexleft,String rgexright){  
        List<String> list = new ArrayList<String>();  
		Pattern pattern = Pattern.compile(rgexleft+"\\w{1,2}"+rgexright);
		Matcher matcher = pattern.matcher(str);
	    while(matcher.find()){
	    	list.add(matcher.group().replaceAll(rgexleft, "").replaceAll(rgexright, "").trim());
	    }
        return list;  
    }  
    
    /** 
     * 正则表达式匹配两个指定字符串中间的内容 
     * @param soap 
     * @return 
     */  
    public static String getDate(String str){  
    	String req="";
    	Pattern pattern = Pattern.compile("[0-9]{4}[-][0-9]{1,2}[-][0-9]{1,2}");  
        Matcher matcher = pattern.matcher(str);  
        String dateStr = null;  
        if(matcher.find()){  
          dateStr = matcher.group(0);  
          req=dateStr.toString();
        }  
        return req;  
    }  
    
    /** 
     * 正则表达式匹配两个指定字符串中间的内容 
     * @param soap 
     * @return 
     */  
    public static String getTime(String str){  
    	String req="";
    	Pattern pattern = Pattern.compile("[0-9]{1,2}[:][0-9]{1,2}");  
        Matcher matcher = pattern.matcher(str);  
        String dateStr = null;  
        if(matcher.find()){  
          dateStr = matcher.group(0);  
          req=dateStr.toString();
        }  
        return req;  
    }  
    
    
    public static String getNumber(String str){  
    	String req="";
    	Pattern pattern = Pattern.compile("】[0-9]{1,3}");  
        Matcher matcher = pattern.matcher(str);  
        String dateStr = null;  
        if(matcher.find()){  
          dateStr = matcher.group(0);  
          req=dateStr.toString();
        }  
        return req;  
    }  
    
    
    
    
    
    
    
	
	
}
