模糊匹配字符的正则表达式+例子
2015-09-10 12:34
190 查看
package com.cn.util;
import java.util.regex.Pattern;
/**
* 正则表达式 工具类
*
* @author lifangyu
*/
public class RegexUtil {
/*
* IP地址的匹配标达式 ( // \\d{1,3}) // :\d // 0~9数字,{1,3} // 至少一位,最多三位)
*/
private static String regex_IP = "^(121.15.215.(\\d{1,3}))$";
/*
* 字符串 模糊匹配 :^(.*张三.*name.*)$ ; 等值匹配 ^(张三)$
*/
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;
}
}
import java.util.regex.Pattern;
/**
* 正则表达式 工具类
*
* @author lifangyu
*/
public class RegexUtil {
/*
* IP地址的匹配标达式 ( // \\d{1,3}) // :\d // 0~9数字,{1,3} // 至少一位,最多三位)
*/
private static String regex_IP = "^(121.15.215.(\\d{1,3}))$";
/*
* 字符串 模糊匹配 :^(.*张三.*name.*)$ ; 等值匹配 ^(张三)$
*/
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;
}
}
相关文章推荐
- 360酷派之争升级 ,“关键人”为何保持缄默?
- ThreadLocal使用
- Win10 Mobile预览版10536升级更新截图曝光:版本号10.0.10536.1003
- javascript----显示日期
- 孙陪你,了解它的力量——unity3d流程暂停
- SysLog简介和java操作实例
- iOS TableView和TableViewCell的风格
- LVS-DR模型简介
- storm-start项目示例和开发-03.docx
- 谷歌回归前景堪忧:狼真来了却落入虎口
- Desktops 虚拟桌面软件(推荐)
- android jni 有感一
- 比较好的js框架和代码学习网站
- ERROR: JDWP Transport dt_socket failed to initialize, TRANSPORT_INIT(510)
- AIDL Android
- http://www.cnblogs.com/huangcong/archive/2010/06/14/1757957.html
- 看懂UML类图和时序图
- Geometric Shapes - POJ 3449(多边形相交)
- jump
- Searching a 2D Sorted Matrix Part II