找到 34423 篇文章 关于编程
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"; //正则表达式接受 ... 阅读更多
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", ... 阅读更多
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" ... 阅读更多
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" ... 阅读更多
3K+ 次浏览
Pattern 类的 DOTALL 字段启用 dotall 模式。默认情况下,正则表达式中的“.”元字符匹配除换行符以外的所有字符。示例 1 import 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()); ... 阅读更多
492 次浏览
Pattern 类的 COMMENTS 字段允许在模式中使用空格和注释。当您将此用作 `compile()` 方法的标志值时,给定模式中的空格和以 # 开头的注释将被忽略。示例 1 import 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"; //编译 ... 阅读更多
2K+ 次浏览
Pattern 类的 CASE_INSENSITIVE 字段不区分大小写地匹配字符。当您将此用作 `compile()` 方法的标志值时,如果使用正则表达式搜索字符,则将匹配两种情况下的字符。注意 - 默认情况下,此标志仅匹配 ASCII 字符示例 1 import 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 ... 阅读更多
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); ... 阅读更多
430 次浏览
java.regex 包的 Pattern 类是正则表达式的编译表示。此类的 compile() 方法接受表示正则表达式的字符串值并返回 Pattern 对象,以下是此方法的签名。static Pattern compile(String regex)此方法的另一个变体接受表示标志的整数值,以下是带有两个参数的 compile 方法的签名。static Pattern compile(String regex, int flags)Pattern 类提供各种字段,每个字段代表一个标志序号字段和描述 1 CANON_EQ 仅当两个字符规范相等时才匹配它们。2 CASE_INSENSITIVE 不区分大小写地匹配字符。3 COMMENTS 允许在模式中使用空格和注释。4 DOTALL 启用 dotall 模式。其中 ... 阅读更多
148 次浏览
java.util.regex 包的 Pattern 类是正则表达式的编译表示。此类的 toString() 方法返回正则表达式的字符串表示,使用该表达式编译当前 Pattern。示例 1 import 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("Enter input string"); String input = sc.nextLine(); //正则表达式查找数字 String regex = "(\d)"; //编译正则表达式 ... 阅读更多
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C语言编程
C++
C#
MongoDB
MySQL
Javascript
PHP