正则表达式定义了字符串的模式。
正则表达式可以用来搜索、编辑或处理文本。
正则表达式并不仅限于某一种语言,但是在每种语言中有细微的差别。
boolean isValidMobileNumber(String s) {
return s.matches("\\d{11}");
}
public class Main {
public static void main(String[] args) {
String regex = "20\\d\\d";
System.out.println("2019".matches(regex)); // true
System.out.println("2100".matches(regex)); // false
}
}
原文:https://www.cnblogs.com/chenshaowei/p/13272305.html