RegexMatches.java

package com.gzz.common.base.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**

  • @summary 【测试正规表达式】
  • @author 高振中
  • @date 2022-05-22 10:00:00
    */
    public class RegexMatches {
    public static void main(String[] args) {
    String sql = "SELECT name FROM table t WHERE t.id=1";// 按指定模式在字符串查找
    String find = "(?i)(SELECT)(.
    )(?i)(FROM)";// 创建 Pattern 对象
    Pattern r = Pattern.compile(find);
    Matcher m = r.matcher(sql);// 现在创建 matcher 对象
    if (m.find()) {
    System.out.println("Found value: " + m.group(0));
    System.out.println("Found value: " + m.group(1));
    System.out.println("Found value: " + m.group(2));
    System.out.println("Found value: " + m.group(3));
    } else {
    System.out.println("NO MATCH");
    }
    }
    }

你可能感兴趣的:(RegexMatches.java)