package com.wy.regular;
public class RegularTest {
public static void main(String[] args) {
/*
* 认识预定义好的特殊字符(Predefined character) \s \w \d
* \d 代表一位数字 [0-9]
* \D 代表的是除了0-9的任何字符 [^0-9]
* \s 代表一个空白字符 [ \t\n\x0B\f\r]
* \t 是Tab键,\n是换行,\x0B是 whitespace,\f是进表符,\r是回车
* \w 代表的是 A word character,构成单词的字符 [a-zA-Z_0-9],特别注意有一个_
* \W 代表的是 [^\w]
*/
pri(" \n\r\t".matches("\\s{4}"));//true
pri(" ".matches("\\S"));//false
pri("a_8".matches("\\w{3}"));//true
pri("abc888&^%".matches("[a-z]{1,3}\\d+[&^#%]+"));//true
// matcher("\\")括号中的是正则表达式,正则表达式本身就需要一个\,第二个\就会和后面的"构成转义字符。
// pri("\\".matches("\\"));//报错PatternSyntaxException
pri("\\".matches("\\\\"));//true
}
public static void pri(Object object){
System.out.println(object);
}
}