1.车牌号校验:
String reg = "^[\u4e00-\u9fa5]{1}[A-Z]{1}[A-Z_0-9]{5}$";
return Pattern.matches(reg, pLicensePlateNo);
2.多个空格替换成一个逗号
searchVal = searchVal.replace(/\s+([^\s]*)/g,",$1");
3.script,style,html正则
REGEX_SCRIPT="<script[^>]*?>[\\s\\S]*?<\\/script>"; //定义script的正则表达式
REGEX_STYLE="<style[^>]*?>[\\s\\S]*?<\\/style>"; //定义style的正则表达式
REGEX_HTML="<[^>]+>"; //定义HTML标签的正则表达式
REGEX_HTTP = "(http://|ftp://|https://|www){0,1}[^\u4e00-\u9fa5\\s]*?\\.com/";//定义域名http://www.xxxx.com/
str.replaceAll("\\[(.*?)\\]","");//过滤英文[]以及里面的内容
str.replaceAll("【.*】", "");//过滤中文【】以及里面的内容
public static String removeHtmlTag(String htmlStr,int type){
if(type >=1 ){
Pattern p_html = Pattern.compile(REGEX_HTML, Pattern.CASE_INSENSITIVE);
Matcher m_html = p_html.matcher(htmlStr);
htmlStr = m_html.replaceAll(""); // 过滤html标签
}
if(type >=2 ){
Pattern p_script = Pattern.compile(REGEX_SCRIPT, Pattern.CASE_INSENSITIVE);
Matcher m_script = p_script.matcher(htmlStr);
htmlStr = m_script.replaceAll(""); // 过滤script标签
}
if(type >=3 ){
Pattern p_script = Pattern.compile(REGEX_STYLE, Pattern.CASE_INSENSITIVE);
Matcher m_script = p_script.matcher(htmlStr);
htmlStr = m_script.replaceAll(""); // 过滤css标签
}
//去除域名http://www.ytsrc1.com
String url = "http://www.zuidaima.com/sdfsdf";
String REGEX_HTTP = "(http://|ftp://|https://|www){0,1}[^\u4e00-\u9fa5\\s]*?\\.com/";
Pattern p_html = Pattern.compile(REGEX_HTTP, Pattern.CASE_INSENSITIVE);
Matcher m_html = p_html.matcher(url);
url = m_html.replaceAll("");
System.out.println(url);
return htmlStr.trim(); // 返回文本字符串
}
4.校验是否为数字
public boolean isNumber(String str)
{
java.util.regex.Pattern pattern=java.util.regex.Pattern.compile("[0-9]*");
java.util.regex.Matcher match=pattern.matcher(str);
if(match.matches()==false)
{
return false;
}
else
{
return true;
}
}
5.邮箱正则
private static final Pattern EMAIL_PATTERN = Pattern
.compile("\\w[-\\w.+]*@([A-Za-z0-9][-A-Za-z0-9]+\\.)+[A-Za-z]{2,14}");
6.电话号码正则
private static final Pattern MOBILE_PATTERN = Pattern.compile("(13|14|15|17|18)[0-9]{9}");
|
|