Java Regex - 模式类

简介

java.util.regex.Pattern 类表示正则表达式的编译表示.

类声明

以下是 java.util.regex.Pattern 类声明&减去;

public final class Pattern
   extends Object
      implements Serializable

字段

以下是 java.util.regex.Duration 的字段&减去;

  • static int CANON_EQ : 启用规范等效.

  • static int CASE_INSENSITIVE : 启用不区分大小写的匹配.

  • static int COMMENTS : 以模式允许空格和注释.

  • static int DOTALL : 启用dotall模式.

  • static int LITERAL : 启用模式的文字解析.

  • static int MULTILINE : 启用多行模式.

  • static int UNICODE_CASE : 启用支持Unicode的案例折叠.

  • static int UNICODE_CHARACTER_CLASS : 启用Unicode版本的预定义字符类和POSIX字符类.

  • static int UNIX_LINES : 启用Unix行模式.

类方法

Sr.No方法&说明
1static Pattern compile(String regex)

将给定的正则表达式编译成模式.

2static Pattern compile(String regex, int flags)

将给定的正则表达式编译成具有给定标志的模式.

3int flags()

返回此模式的匹配标志.

4Matcher matcher(CharSequence input)

创建一个匹配此模式的给定输入的匹配器.

5static boolean matches(String regex, CharSequence input) 

编译给定的正则表达式并尝试匹配给定的输入.

6String pattern()

返回编译此模式的正则表达式.

7static String quote(String s)

返回指定字符串的文字模式字符串.

8String [] split(CharSequence input)

围绕此模式的匹配拆分给定的输入序列.

9String [] split(CharSequence input,int limit)

围绕此模式的匹配拆分给定的输入序列.

10String toString()

返回此模式的字符串表示形式.

继承的方法

此类继承以下类中的方法 :

  • Java.lang.Object