找到 34423 篇文章 关于编程

Java 中使用 Pattern 的 UNIX_LINES 字段及示例

Maruthi Krishna
更新于 2024年8月8日 12:56:52

250 次浏览

此标志启用 Unix 行模式。在 Unix 行模式下,仅使用 '' 作为行终止符,而 ' \r' 被视为文字字符。示例 1 import java.util.regex.Matcher; import java.util.regex.Pattern; public class LTERAL_Example { public static void main(String[] args) { String input = "This is the first line\r" + "This is the second line\r" + "This is the third line\r"; //正则表达式接受 ... 阅读更多

Java 中使用 Pattern 的 UNICODE_CASE 字段及示例

Maruthi Krishna
更新于 2023年12月7日 10:03:09

941 次浏览

启用 Unicode 感知大小写折叠。当您将此用作标志值传递给 compile() 方法以及 CASE_INSENSITIVE 标志,并且如果您使用正则表达式搜索 Unicode 字符时,将匹配两种情况下的 Unicode 字符。示例 import java.util.regex.Matcher; import java.util.regex.Pattern; public class UNICODE_CASE_Example { public static void main( String args[] ) { String regex = "\u00de"; //编译正则表达式 Pattern pattern = Pattern.compile(regex, Pattern.UNICODE_CASE|Pattern.CASE_INSENSITIVE); //检索匹配器对象 String str[] = {"\u00de", "\u00fe", ... 阅读更多

Java 中使用 Pattern 的 MULTILINE 字段及示例

Maruthi Krishna
更新于 2023年12月5日 10:40:19

2K+ 次浏览

在一般情况下启用多行模式,^ 和 $ 元字符匹配给定输入的开头和结尾,并使用指定的字符,而不管其中的行数。示例 1 import java.util.regex.Matcher; import java.util.regex.Pattern; public class MULTILINE_Example { public static void main( String args[] ) { //String regex = "(^This)";//.*t$)"; String input = "2234 This is a sample text" + "1424 This second 2335 line" + "This id third 455 line" ... 阅读更多

Java 中使用 Pattern 的 LITERAL 字段及示例

Maruthi Krishna
更新于 2023年12月5日 10:52:51

1K+ 次浏览

启用模式的逐字解析。在这种情况下,包括转义序列和元字符在内的所有字符都没有任何特殊含义,它们被视为文字字符。例如,通常,如果您在给定的输入文本中搜索正则表达式“^This”,它将匹配以“This”一词开头的行。示例 1 import java.util.regex.Matcher; import java.util.regex.Pattern; public class LTERAL_Example { public static void main(String[] args) { String input = "This is the first line" + "This is the second line" ... 阅读更多

Java 中使用 Pattern 的 DOTALL 字段及示例

Maruthi Krishna
更新于 2019年11月20日 06:09:35

3K+ 次浏览

Pattern 类的 DOTALL 字段启用 dotall 模式。默认情况下,正则表达式中的“.”元字符匹配除换行符之外的所有字符。示例 1import java.util.regex.Matcher; import java.util.regex.Pattern; public class DOTALL_Example {    public static void main( String args[] ) {       String regex = ".";       String input = "this is a sample this is second line";       Pattern pattern = Pattern.compile(regex);       Matcher matcher = pattern.matcher(input);       int count =0;       while(matcher.find()) {          count++;          System.out.print(matcher.group());     ... 阅读更多

Java 中使用 Pattern 的 COMMENTS 字段及示例

Maruthi Krishna
更新于 2019年11月20日 06:07:37

492 次浏览

Pattern 类的 COMMENTS 字段允许在模式中使用空格和注释。当您将此用作标志值传递给 compile() 方法时,给定模式中的空格和以 # 开头的注释将被忽略。示例 1import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class COMMENTES_Example {    public static void main( String args[] ) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter input data: ");       String input = sc.nextLine();       //正则表达式查找数字       String regex = "\d #ignore this comment";       //编译 ... 阅读更多

Java 中使用 Pattern 的 CASE_INSENSITIVE 字段及示例

Maruthi Krishna
更新于 2019年11月20日 06:05:24

2K+ 次浏览

Pattern 类的此 CASE_INSENSITIVE 字段匹配字符,而不管大小写。当您将此用作标志值传递给 compile() 方法,并且如果您使用正则表达式搜索字符时,将匹配两种情况下的字符。注意 - 默认情况下,此标志仅匹配 ASCII 字符示例 1import java.util.Scanner; import java.util.regex.Matcher; import java.util.regex.Pattern; public class CASE_INSENSITIVE_Example {    public static void main( String args[] ) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter input data: ");       String input = sc.nextLine();       System.out.println("Enter required character: ");       char ... 阅读更多

Java 中使用 Pattern 的 CANON_EQ 字段及示例

Maruthi Krishna
更新于 2023年12月6日 12:36:04

1K+ 次浏览

Pattern 类的 CANON_EQ 字段仅当两个字符规范等价时才匹配它们。当您将此用作标志值传递给 compile() 方法时,当且仅当两个字符的完整规范分解相等时,才会匹配这两个字符。其中规范分解是 Unicode 文本规范化形式之一。示例 1 import java.util.regex.Matcher; import java.util.regex.Pattern; public class CANON_EQ_Example { public static void main( String args[] ) { String regex = "b\u0307"; //编译正则表达式 Pattern pattern = Pattern.compile(regex, Pattern.CANON_EQ); ... 阅读更多

Java 中使用 Pattern 的 flags() 方法及示例

Maruthi Krishna
更新于 2019年11月20日 05:59:25

430 次浏览

java.regex 包的 Pattern 类是正则表达式的编译表示形式。此类的 compile() 方法接受表示正则表达式的字符串值并返回一个 Pattern 对象,以下是此方法的签名。static Pattern compile(String regex)此方法的另一个变体接受表示标志的整数值,以下是带有两个参数的 compile 方法的签名。static Pattern compile(String regex, int flags)Pattern 类提供各种字段,每个字段代表一个标志序号字段和描述1CANON_EQ仅当两个字符规范等价时才匹配它们。2CASE_INSENSITIVEMatches characters irrespective of case.3COMMENTSAllows whitespace and comments in pattern.4DOTALLEnables dotall mode. Where ... 阅读更多

Java 中使用 Pattern 的 toString() 方法及示例

Maruthi Krishna
更新于 2019年11月20日 05:54:48

148 次浏览

java.util.regex 包中的 Pattern 类是正则表达式的编译表示形式。此类的 toString() 方法返回正则表达式的字符串表示形式,使用该字符串表示形式编译当前的 Pattern。示例 1import java.util.Scanner; import java.util.regex.Pattern; public class Example {    public static void main( String args[] ) {       //读取字符串值       Scanner sc = new Scanner(System.in);       System.out.println("输入字符串");       String input = sc.nextLine();       //查找数字的正则表达式       String regex = "(\d)";       //编译正则表达式 ... 阅读更多

广告

© . All rights reserved.