正则、字符类Pattern、Matcher类

字符类
 * [abc] a、b 或 c(简单类)
 * [^abc] 任何字符,除了 a、b 或 c(否定)
 * [a-zA-Z] a到 z 或 A到 Z,两头的字母包括在内(范围)
 * [0-9] 0到9的字符都包括
 * . 任何字符。
 * \d 数字:[0-9]
 * \w 单词字符:[a-zA-Z_0-9]

  ? ,一次或一次也没有
  * ,零次或多次
  + ,一次或多次
  {n} ,恰好 n 次
 {n,} ,至少 n 次
 {n,m} ,至少 n 次,但是不超过 m 次

正则表达式的分割功能
 * String类的功能:public String[] split(String regex)

正则表达式的替换功能
 * String类的功能:public String replaceAll(String regex,String replacement)
 
Pattern和Matcher
 * Pattern p = Pattern.compile("a*b");
 * Matcher m = p.matcher("aaaaab");
 * boolean b = m.matches();

猜你喜欢

转载自www.cnblogs.com/wuxu/p/10649381.html