Home > Web Front-end > JS Tutorial > Example of fuzzy matching function of characters implemented by regular expression_regular expression

Example of fuzzy matching function of characters implemented by regular expression_regular expression

微波
Release: 2017-06-28 13:35:31
Original
3451 people have browsed it

这篇文章主要介绍了正则表达式实现字符的模糊匹配功能,结合具体java实例形式分析了针对字符串的模糊匹配查询相关实现技巧,需要的朋友可以参考下

本文实例讲述了正则表达式实现字符的模糊匹配功能。分享给大家供大家参考,具体如下:

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;
  }
}
Copy after login

PS:这里再为大家提供2款非常方便的正则表达式工具供大家参考使用:

JavaScript正则表达式在线测试工具:
http://tools.jb51.net/regex/javascript

正则表达式在线生成工具:
http://tools.jb51.net/regex/create_reg

The above is the detailed content of Example of fuzzy matching function of characters implemented by regular expression_regular expression. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template