找到 34423 篇文章,关于编程
411 次浏览
find() 方法查找与所需模式匹配的输入序列中的子序列。此方法在 java.util.regex 包中提供的 Matcher 类中可用。演示 Java 正则表达式中 Matcher.find() 方法的程序如下所示:示例 在线演示import java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo { public static void main(String args[]) { Pattern p = Pattern.compile("Sun"); Matcher m = p.matcher("The Earth revolves around the Sun"); System.out.println("子序列:Sun"); System.out.println("序列:The Earth revolves around the Sun"); if (m.find()) ... 阅读更多
114 次浏览
java.util.regex.Matcher.end() 方法返回根据正则表达式从序列中匹配的最后一个字符后的偏移值。此方法不需要参数。如果未发生匹配或匹配操作失败,则抛出 IllegalStateException。演示 Java 正则表达式中 Matcher.end() 方法的程序如下所示:示例 在线演示import java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo { public static void main(String args[]) { Pattern p = Pattern.compile("(a*b)"); Matcher m = p.matcher("caaabccaab"); System.out.println("输入字符串是:caaabccaab"); System.out.println("正则表达式是:(a*b)"); ... 阅读更多
122 次浏览
字符类是一组括在方括号内的字符。字符类中的字符指定可以与输入字符串中的字符匹配以获得成功的字符。字符类的示例是 [a-z],它表示字母 a 到 z。演示 Java 正则表达式中字符类的程序如下所示:示例 在线演示import java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo { public static void main(String args[]) { Pattern p = Pattern.compile("[a-z]+"); Matcher m = p.matcher("the sky is blue"); System.out.println("输入... 阅读更多
154 次浏览
一般来说,? 量词表示指定模式的 0 次或 1 次出现。例如 - X? 表示 X 的 0 次或 1 次出现。正则表达式 "t.+?m" 用于使用 ? 量词在字符串 "tom and tim are best friends" 中查找匹配项。演示此功能的程序如下所示:示例 在线演示import java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo { public static void main(String args[]) { Pattern p = Pattern.compile("t.+?m"); Matcher m = p.matcher("tom and tim are best friends"); System.out.println("输入字符串是:tom and tim are best ... 阅读更多
60 次浏览
find() 方法查找与所需模式匹配的输入序列中的子序列。此方法在 java.util.regex 包中提供的 Matcher 类中可用。使用 find() 方法在 Java 中查找子序列的程序如下所示:示例 在线演示import java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo { public static void main(String args[]) { Pattern p = Pattern.compile("cool"); Matcher m = p.matcher("Java is cool"); System.out.println("子序列:cool"); System.out.println("序列:Java is cool"); if (m.find()) System.out.println("找到子序列"); ... 阅读更多
135 次浏览
勉强量词从尽可能短的字符串大小开始。如果引擎找到匹配项,则继续查找更多匹配项,否则引擎向搜索字符串部分添加字符并再次尝试。这将持续进行,直到获得匹配项或用完字符串。正则表达式 "B+?" 用于在字符串 "SkyIsBlue" 中查找匹配项。演示此功能的程序如下所示:示例 在线演示import java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo { public static void main(String args[]) { String regex = "B+?"; String str ... 阅读更多
4K+ 次浏览
对象可以使用继承来获取另一个对象的属性和行为。在 Java 中,extends 关键字用于指示新类是使用继承从基类派生的。因此,基本上,extends 关键字用于扩展类的功能。演示 Java 中 extends 关键字的程序如下所示:示例 在线演示class A { int a = 9; } class B extends A { int b = 4; } public class Demo { public static void main(String args[]) { B obj = new B(); ... 阅读更多
734 次浏览
Java 中的 null 是 null 类型的文字量。它不能转换为 int、float 等原始类型,但可以转换为引用类型。此外,null 的值不一定为 0。演示 Java 中 null 的程序如下所示:示例 在线演示public class Demo { public static void main(String args[]) { String str = null; System.out.println("str 的值为:" + str); } }输出str 的值为:null现在让我们了解上面的程序。在 main() 方法中,String str 初始化为... 阅读更多
195 次浏览
贪婪量词尽可能多次重复指定的标记,然后引擎回溯,贪婪量词放弃匹配以最终找到所需的匹配项。正则表达式 "(\w+)(\d)(\w+)" 用于在字符串 "EarthHas1Moon" 中查找匹配项。演示此功能的程序如下所示:示例 在线演示import java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo { public static void main(String args[]) { String str = "EarthHas1Moon"; String regex = "(\w+)(\d)(\w+)"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(str); m.find(); ... 阅读更多
540 次浏览
可以使用Java正则表达式查找以字母“a”开头的所有单词。正则表达式是字符序列,可以使用特定的模式语法与其他字符串匹配。正则表达式位于java.util.regex包中,该包包含许多类,但最重要的类是Pattern类和Matcher类。以下是一个使用正则表达式查找所有以“a”开头的单词的程序示例:示例 在线演示import java.util.regex.Matcher; import java.util.regex.Pattern; public class Demo { public static void main(String args[]) throws Exception { String ... 阅读更多
数据结构
网络
关系数据库管理系统 (RDBMS)
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP