zl程序教程

您现在的位置是:首页 >  后端

当前栏目

Java经典实例:使用正则表达式:测试模式详解编程语言

2023-06-13 09:20:45 时间
String pattern = "^Q[^u]//d+//."; String[] input = {"QA777. is the next flight. It is on time.", "Quack, Quack, Quack!"}; Pattern p = Pattern.compile(pattern); for (String s : input) { /** * 在字符串中匹配模式,从字符串的首字母开始,或者之前已经成功调用该方法,则从未能符合前面匹配的第一个字符开始 boolean found = p.matcher(s).find(); System.out.println("" + pattern + " " + (found ? " matches " : "doesnt match ") + s + ""); }

 输出:

^Q[^u]/d+/. matches QA777. is the next flight. It is on time. 

^Q[^u]/d+/. doesnt match Quack, Quack, Quack!

 

15870.html

cjava