📜  Java正则表达式-模式类

📅  最后修改于: 2020-11-14 10:18:43             🧑  作者: Mango


介绍

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-启用预定义字符类和POSIX字符类的Unicode版本。

  • static int UNIX_LINES-启用Unix行模式。

类方法

Sr.No Method & Description
1 static Pattern compile(String regex)

Compiles the given regular expression into a pattern.

2 static Pattern compile(String regex, int flags)

Compiles the given regular expression into a pattern with the given flags.

3 int flags()

Returns this pattern’s match flags.

4 Matcher matcher(CharSequence input)

Creates a matcher that will match the given input against this pattern.

5 static boolean matches(String regex, CharSequence input)

Compiles the given regular expression and attempts to match the given input against it.

6 String pattern()

Returns the regular expression from which this pattern was compiled.

7 static String quote(String s)

Returns a literal pattern String for the specified String.

8 String[] split(CharSequence input)

Splits the given input sequence around matches of this pattern.

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

Splits the given input sequence around matches of this pattern.

10 String toString()

Returns the string representation of this pattern.

方法继承

此类从以下类继承方法-

  • Java.lang.Object