package cn.mldn.demo; public class TestDemo { public static void main(String[] args) throws Exception { String str = "SMITH" ; String regex = "[a-zA-Z]+" ; System.out.println(str.matches(regex)); } } |
package cn.mldn.demo; public class TestDemo { public static void main(String[] args) throws Exception { String str = "19" ; String regex = "\\d{1,3}" ; System.out.println(str.matches(regex)); } } |
package cn.mldn.demo; public class TestDemo { public static void main(String[] args) throws Exception { String str = "1998-08-01" ; String regex = "\\d{4}-\\d{2}-\\d{2}" ; System.out.println(str.matches(regex)); } } |
package cn.mldn.demo; public class TestDemo { public static void main(String[] args) throws Exception { String str = "98.12" ; String regex = "\\d{1,3}(\\.\\d{1,2})?" ; System.out.println(str.matches(regex)); } } |
package cn.mldn.demo; public class TestDemo { public static void main(String[] args) throws Exception { String str = "SMITH:20:1990-09-15:90.9" ; String regex= "[a-zA-Z]+:\\d{1,3}:\\d{4}-\\d{2}-\\d{2}:\\d{1,3}(\\.\\d{1,2})?" ; System.out.println(str.matches(regex)); } } |
package cn.mldn.demo; public class TestDemo { public static void main(String[] args) throws Exception { String str = "SMITH:20:1990-09-15:90.9|ALLEN:19:1991-11-11:89.6|TONY:21:1989-07-28:100" ; String regex = "([a-zA-Z]+:\\d{1,3}:" + "\\d{4}-\\d{2}-\\d{2}:" + "\\d{1,3}(\\.\\d{1,2})?\\|?)+" ; System.out.println(str.matches(regex)); } } |
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |