继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

java正则学习笔记

萌萌小温柔
关注TA
已关注
手记 306
粉丝 56
获赞 401

public class Demo3_Regex {

/** *  . 任何字符    \d 数字:[0-9]     \D 非数字: [^0-9]     \s 空白字符:[ \t\n\x0B\f\r]     \S 非空白字符:[^\s]     \w 单词字符:[a-zA-Z_0-9]     \W 非单词字符:[^\w]  */public static void main(String[] args) {    //demo1();    //demo2();    //demo3();    //demo4();    //demo5();    //demo6();    String regex = "\\W";    System.out.println("a".matches(regex));    System.out.println("z".matches(regex));    System.out.println("_".matches(regex));    System.out.println("%".matches(regex));}private static void demo6() {    String regex = "\\w";    System.out.println("a".matches(regex));    System.out.println("z".matches(regex));    System.out.println("_".matches(regex));    System.out.println("%".matches(regex));}private static void demo5() {    String regex = "\\S";    System.out.println(" ".matches(regex));    System.out.println("    ".matches(regex));    System.out.println("a".matches(regex));}private static void demo4() {    String regex = "\\s";    System.out.println(" ".matches(regex));    System.out.println("    ".matches(regex));              //一个tab键    System.out.println("    ".matches(regex));              //四个空格}private static void demo3() {    String regex = "\\D";    System.out.println("0".matches(regex));    System.out.println("9".matches(regex));    System.out.println("a".matches(regex));}private static void demo2() {    String regex = "\\d";                   //\代表转义字符,如果想表示\d的话,需要\\d    System.out.println("0".matches(regex));    System.out.println("a".matches(regex));    System.out.println("9".matches(regex));}private static void demo1() {    String regex = "..";    System.out.println("a".matches(regex));    System.out.println("ab".matches(regex));}

}

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP