1.概述
正则表达式(regular expression)描述了一种字符串匹配的模式(pattern),
可以用来检查一个串是否含有某种子串、将匹配的子串替换或者从某个串中取出符合某个条件的子串等。
2.限定符
1.英文 . 匹配单个任意字符
//a.b -> aab , abb, abc 正确 aaab accb ->不正确
String s = new String("abcb");
boolean matches = s.matches("a.b");//false
2.[] 匹配括号中的单个符号
String s = new String("1abc");
boolean matches = s.matches("[0-9]abc");//true
3、| 符号。相当与“或”,可以匹配指定的字符,但是也只能选择其中一项进行匹配。
String s = new String("aabc");
boolean matches = s.matches("a(ab|a|c)c");//true