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

Jun 28, 2017 pm 01:35 PM
character Vague expression

这篇文章主要介绍了正则表达式实现字符的模糊匹配功能,结合具体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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to blur photos with Yitian camera How to blur photos with Yitian camera Feb 23, 2024 pm 06:40 PM

You can blur the photos in Yitian Camera, so how to blur the photos? Users can click Edit to select a photo, then click Effects and select Blur to blur the photo. This introduction to how to blur photos can tell you the specific content. The following is a detailed introduction, come and take a look! Yitian Camera usage tutorial. How to blur photos with Yitian Camera. Answer: Go to Edit-Special Effects-Blur. The specific process: 1. First open the app and click Edit on the lower left. 2. Then click on a picture and click the edit button. 3. Then click the special effects button below. 4. You can find the blur function below. 5. Then select the magnification of the blur.

Use java's Character.isDigit() function to determine whether a character is a number Use java's Character.isDigit() function to determine whether a character is a number Jul 27, 2023 am 09:32 AM

Use Java's Character.isDigit() function to determine whether a character is a numeric character. Characters are represented in the form of ASCII codes internally in the computer. Each character has a corresponding ASCII code. Among them, the ASCII code values ​​corresponding to the numeric characters 0 to 9 are 48 to 57 respectively. To determine whether a character is a number, you can use the isDigit() method provided by the Character class in Java. The isDigit() method is of the Character class

How to type arrows in Word How to type arrows in Word Apr 16, 2023 pm 11:37 PM

How to use AutoCorrect to type arrows in Word One of the fastest ways to type arrows in Word is to use the predefined AutoCorrect shortcuts. If you type a specific sequence of characters, Word automatically converts those characters into arrow symbols. You can draw many different arrow styles using this method. To type an arrow in Word using AutoCorrect: Move your cursor to the location in the document where you want the arrow to appear. Type one of the following character combinations: If you don't want what you type to be corrected to an arrow symbol, press the backspace key on your keyboard to

How to apply superscript and subscript formatting options in Microsoft Excel How to apply superscript and subscript formatting options in Microsoft Excel Apr 14, 2023 pm 12:07 PM

A superscript is a character or characters, either letters or numbers, that you need to set slightly above the normal line of text. For example, if you need to write 1st, the letter st needs to be slightly higher than the character 1. Likewise, a subscript is a group of characters or a single character and needs to be set slightly lower than normal text level. For example, when you write a chemical formula, you need to place the numbers below the normal line of characters. The following screenshots show some examples of superscript and subscript formatting. Although it may seem like a daunting task, applying superscript and subscript formatting to your text is actually quite simple. In this article, we will explain in some simple steps how to easily format text using superscript or subscript. Hope you enjoyed reading this article. How to apply superscript in Excel

How do you enter extended characters, such as the degree symbol, on iPhone and Mac? How do you enter extended characters, such as the degree symbol, on iPhone and Mac? Apr 22, 2023 pm 02:01 PM

Your physical or numeric keyboard provides a limited number of character options on the surface. However, there are several ways to access accented letters, special characters, and more on iPhone, iPad, and Mac. The standard iOS keyboard gives you quick access to uppercase and lowercase letters, standard numbers, punctuation, and characters. Of course, there are many other characters. You can choose from letters with diacritics to upside-down question marks. You may have stumbled upon a hidden special character. If not, here's how to access them on iPhone, iPad, and Mac. How to Access Extended Characters on iPhone and iPad Getting extended characters on your iPhone or iPad is very simple. In "Information", "

How to solve the problem of blurry wallpaper in win11 How to solve the problem of blurry wallpaper in win11 Jan 02, 2024 pm 09:05 PM

Sometimes the wallpaper is blurred when using Win11. I don’t know what’s going on. In fact, we can solve it by modifying the registry or application compatibility. Win11 wallpaper blur solution: 1. Desktop blur 1. If the desktop is blurred, you can right-click the bottom start menu and open "Run" 2. Then enter "regedit" and press Enter to open the registry. 3. After opening, go to the "Computer\HKEY_CURRENT_USER\ControlPanel\Desktop" location. 4. After entering, right-click on the blank space and select Create a new "DWORD Value" 5. Rename it to "JPEGImportQuality" and double-click to open the data.

Correct way to display Chinese characters in matplotlib Correct way to display Chinese characters in matplotlib Jan 13, 2024 am 11:03 AM

Correctly displaying Chinese characters in matplotlib is a problem often encountered by many Chinese users. By default, matplotlib uses English fonts and cannot display Chinese characters correctly. To solve this problem, we need to set the correct Chinese font and apply it to matplotlib. Below are some specific code examples to help you display Chinese characters correctly in matplotlib. First, we need to import the required libraries: importmatplot

Solution: Win7 display is blurry and has ghosting Solution: Win7 display is blurry and has ghosting Jul 14, 2023 pm 09:41 PM

Some Win7 customers have experienced monitor blur and ghosting, resulting in a poor visual experience. What should we do in this situation? You can first open the monitor's settings control panel to see if there is any ghosting in the above content. If there is a problem, please repair the monitor immediately; if not, you can check the monitor's electrode cable to see if it is plugged in or the plug is deformed. Different situations must be handled differently. Solution: Win7 display is blurry and has ghosting. 1. First adjust it to the display's settings menu page to check whether the text on the display's settings menu has a drag shadow. If it is, it proves that the monitor is at fault and the monitor should be repaired immediately. If the monitor's setup menu shows no ghosting, there should be nothing wrong with the monitor itself.

See all articles