string类中的matches方法:

public boolean matches(String regex) {
return Pattern.matches(regex, this);
}

 

java  Pattern类

 

思考题:

/* 需求:把一个字符串中的手机号码获取出来*/



Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(s);

/*boolean b1 = m.find();
System.out.println(b1);
System.out.println(m.group());

boolean b2 = m.find();
System.out.println(b2);
System.out.println(m.group());*/

while(m.find())
System.out.println(m.group());

相关文章:

  • 2022-02-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-25
  • 2021-10-20
  • 2022-02-13
猜你喜欢
  • 2021-12-24
  • 2022-12-23
  • 2021-12-07
  • 2021-06-10
  • 2021-12-16
  • 2021-11-19
相关资源
相似解决方案