(3)使用预定义字符
.
\d
\D
\s
\S
\w
\W
import java.util.regex.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
public class Test
{
public static void main(String[] args) throws Exception
{
//正则表达式的预定义字符
//.
Pattern p = Pattern.compile(".");
Matcher m = p.matcher("\n");
System.out.println(m.matches());
// \d
p = Pattern.compile("\\d");
m = p.matcher("6");
System.out.println(m.matches());
// \D
System.out.println(Pattern.matches("\\D","a"));
//\s
System.out.println(Pattern.matches("\\s","\t"));
// \S
System.out.println(Pattern.matches("\\S","1"));
// \w
System.out.println(Pattern.matches("\\w","_"));
//\W
System.out.println(Pattern.matches("\\W","我"));
}
}