Class OpenRegex

java.lang.Object
cloud.opencode.base.string.regex.OpenRegex

public final class OpenRegex extends Object
Regex Facade - Unified entry point for regex matching and validation operations. 正则门面 - 正则匹配和验证操作的统一入口。

Features | 主要功能:

  • Pattern matching and extraction - 模式匹配和提取
  • ReDoS protection via pattern length limit - 通过模式长度限制防止ReDoS
  • Convenient static match/find/replace methods - 便捷的静态匹配/查找/替换方法

Usage Examples | 使用示例:

boolean matches = OpenRegex.matches("\\d+", "12345");
List<String> found = OpenRegex.findAll("\\d+", "a1b2c3");
String replaced = OpenRegex.replaceAll("\\d", "abc123", "*");

Security | 安全性:

  • Thread-safe: Yes (stateless utility) - 线程安全: 是(无状态工具类)
  • Null-safe: No (input must not be null) - 空值安全: 否(输入不能为空)
Since:
JDK 25, opencode-base-string V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • matches

      public static boolean matches(String str, String regex)
    • matches

      public static boolean matches(String str, Pattern pattern)
    • contains

      public static boolean contains(String str, String regex)
    • findFirst

      public static String findFirst(String str, String regex)
    • findAll

      public static List<String> findAll(String str, String regex)
    • findGroup

      public static String findGroup(String str, String regex, int group)
    • findAllGroups

      public static List<String[]> findAllGroups(String str, String regex)
    • findNamedGroups

      public static Map<String,String> findNamedGroups(String str, String regex)
    • replaceFirst

      public static String replaceFirst(String str, String regex, String replacement)
    • replaceAll

      public static String replaceAll(String str, String regex, String replacement)
    • replaceAll

      public static String replaceAll(String str, String regex, Function<String,String> replacer)
    • split

      public static String[] split(String str, String regex)
    • split

      public static String[] split(String str, String regex, int limit)
    • escape

      public static String escape(String str)
    • compile

      public static Pattern compile(String regex)
    • compileIgnoreCase

      public static Pattern compileIgnoreCase(String regex)
    • countMatches

      public static int countMatches(String str, String regex)
    • findPositions

      public static List<int[]> findPositions(String str, String regex)
    • isEmail

      public static boolean isEmail(String str)
      Checks if string is a valid email address. 检查字符串是否为有效的电子邮件地址。
      Parameters:
      str - the string to check | 要检查的字符串
      Returns:
      true if valid email | 如果是有效邮箱返回true
    • isUrl

      public static boolean isUrl(String str)
      Checks if string is a valid URL. 检查字符串是否为有效的URL。
      Parameters:
      str - the string to check | 要检查的字符串
      Returns:
      true if valid URL | 如果是有效URL返回true
    • isMobile

      public static boolean isMobile(String str)
      Checks if string is a valid mobile phone number (China). 检查字符串是否为有效的手机号码(中国)。
      Parameters:
      str - the string to check | 要检查的字符串
      Returns:
      true if valid mobile number | 如果是有效手机号返回true
    • isIdCard

      public static boolean isIdCard(String str)
      Checks if string is a valid ID card number (China). 检查字符串是否为有效的身份证号码(中国)。
      Parameters:
      str - the string to check | 要检查的字符串
      Returns:
      true if valid ID card | 如果是有效身份证号返回true
    • isIpv4

      public static boolean isIpv4(String str)
      Checks if string is a valid IPv4 address. 检查字符串是否为有效的IPv4地址。
      Parameters:
      str - the string to check | 要检查的字符串
      Returns:
      true if valid IPv4 | 如果是有效IPv4返回true
    • isUuid

      public static boolean isUuid(String str)
      Checks if string is a valid UUID format. 检查字符串是否为有效的UUID格式。
      Parameters:
      str - the string to check | 要检查的字符串
      Returns:
      true if valid UUID | 如果是有效UUID返回true