最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
实例:正则表达式实现字符的模糊匹配功能
时间:2022-06-30 10:50:29 编辑:袖梨 来源:一聚教程网
本文实例讲述了正则表达式实现字符的模糊匹配功能。分享给大家供大家参考,具体如下:
代码如下 | 复制代码 |
packagecom.cn.util; importjava.util.regex.Pattern; /** * 正则表达式 工具类 * * @author lifangyu */ publicclassRegexUtil { /* * 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.*)$"; /* * 字符不包含特定字符串的表达式 */ privatestaticString regex_notcontainStr ="^(?!.*(转发)).*$";// 不包含特定字符串的表达式 publicstaticvoidmain(String[] args) { System.out.println(StringMatchRule("这个邮件 是转发的!", regex_notcontainStr)); } publicstaticbooleanStringMatchRule(String souce, String regex) { booleanresult =false; if(regex !=null&& souce !=null) { result = Pattern.matches(regex, souce); } returnresult; } } |
相关文章
- 四海兄弟故乡人物边缘模糊怎么办 人物边缘模糊解决方法 08-21
- 四海兄弟故乡神秘狐狸06怎么找 神秘狐狸06位置介绍 08-21
- 四海兄弟故乡神秘狐狸05怎么找 神秘狐狸05位置说明 08-21
- 诛仙2四海战歌奇遇怎么做 四海战歌东海奇遇收集 08-21
- 四海兄弟故乡神秘狐狸04怎么找 神秘狐狸04位置一览 08-21
- 四海兄弟故乡城市有多少 城市地点背景介绍 08-21