南猫猫猫猫猫

导航

正则,java匹配

1.判断字符串中是否全为英文
boolean result = str.matches("[a-zA-Z]+"); //true:全文英文
`str.matches("[a-zA-Z0-9]+") //判断英文和数字`````

2.提取字符串中所有的英文
str = str.replaceAll("[^a-z^A-Z]", ""); //"[^a-z^A-Z]"改为"[^a-z^A-Z^0-9]"即获取所有的英文和数字

3.判断字符串中是否含英文
String regex = ".*[a-zA-z].*";

str.matches(regex); //true:含有英文

posted on 2022-09-23 09:48  南猫猫猫猫猫  阅读(34)  评论(0编辑  收藏  举报