本文实例讲述了正则表达式实现字符的模糊匹配功能。分享给大家供大家参考,具体如下:
package com.cn.util;
import java.util.regex.Pattern;
public class RegexUtil {
private static String regex_IP = "^(121.15.215.(\d{1,3}))$";
private static String regex_containStr = "^(.*张三.*name.*)$";
private static String regex_notcontainStr = "^(?!.*(转发)).*$";// 不包含特定字符串的表达式
public static void main(String[] args) {
System.out.println(StringMatchRule("这个邮件 是转发的!", regex_notcontainStr));
}
public static boolean StringMatchRule(String souce, String regex) {
boolean result = false;
if (regex != null && souce != null) {
result = Pattern.matches(regex, souce);
}
return result;
}
}
PS:这里再为大家提供2款非常方便的正则表达式工具供大家参考使用:
Javascript正则表达式在线测试工具:
http://tools.jb51.net/regex/javascript
正则表达式在线生成工具:
http://tools.jb51.net/regex/create_reg
希望本文所述对大家正则表达式学习有所帮助。



