提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
类模式和匹配器。
import java.util.regex.Matcher; /* N o w J a v a . c o m 提供 */ import java.util.regex.Pattern; public class Main { public static void main(String[] args) { // create regular expression Pattern expression = Pattern.compile("J.*\\d[0-35-9]-\\d\\d-\\d\\d"); String string1 = "Jane's Birthday is 05-12-75\n" + "Dave's Birthday is 11-04-68\n" + "John's Birthday is 04-28-73\n" + "Joe's Birthday is 12-17-77"; /** 时 代 J a v a 公 众 号 提 供 **/ // match regular expression to string and print matches