正则表达式

做了一个关于邮箱验证的正则表达式

 

/** Email的正则表达式 **/
    private static Pattern      emailPattern    = Pattern.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");

/**
     * 判断是否为正确的email地址
     * 
     * @param emailStr
     * @return
     */
    public static boolean isValidEmail(String emailStr) {
        Matcher matcher = emailPattern.matcher(emailStr);
        return matcher.matches();
    }

 

再来一个替换功能:

import java.util.ArrayList;   
import java.util.List;   
import java.util.regex.Matcher;   
import java.util.regex.Pattern;   
  
public class Regx {   
  
    public static void modify(String source){   
        Pattern pattern = Pattern.compile("type=(.+?)>");   
           
        Matcher matcher = pattern.matcher(source);   
        List<String> list = new ArrayList<String>();   
           
        while(matcher.find()){   
               
            list.add(matcher.group(1));   
        }   
           
        for(String each : list){   
            source = source.replaceAll(each, "'"+each+"'");   
        }   
           
        System.out.println(source);   
    }   
       
    public static void main(String[] args) {   
          
           
        Regx.modify("<table><tr><td type=radion>1</td><td type=text>2</td><td type=button>3</td></tr></table>");   
    }   
  
}  

 

你可能感兴趣的:(java,正则表达式)