本文實(shí)例講述了正則表達(dá)式實(shí)現(xiàn)字符的模糊匹配功能。分享給大家供大家參考,具體如下:
package com.cn.util;import java.util.regex.Pattern;/** * 正則表達(dá)式 工具類 * * @author lifangyu */public class RegexUtil { /* * IP地址的匹配標(biāo)達(dá)式 ( // //d{1,3}) // :/d // 0~9數(shù)字,{1,3} // 至少一位,最多三位) */ private static String regex_IP = "^(121.15.215.(//d{1,3}))$"; /* * 字符串 模糊匹配 :^(.*張三.*name.*)$ ; 等值匹配 ^(張三)$ */ private static String regex_containStr = "^(.*張三.*name.*)$"; /* * 字符不包含特定字符串的表達(dá)式 */ private static String regex_notcontainStr = "^(?!.*(轉(zhuǎn)發(fā))).*$";// 不包含特定字符串的表達(dá)式 public static void main(String[] args) { System.out.println(StringMatchRule("這個郵件 是轉(zhuǎn)發(fā)的!", 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; }}
希望本文所述對大家正則表達(dá)式學(xué)習(xí)有所幫助。
|
新聞熱點(diǎn)
疑難解答
圖片精選