团队,
我有一个任务。即,我想检查 blcvk 数据中的 98%
。
我试图编写一些正则表达式,但它给出了连续的错误。
String str="OAM-2 OMFUL abmasc01 and prdrot01 98% users NB in host nus918pe locked.";
if(str.matches("[0-9][0-9]%"))
但它返回 false。
非常感谢您的回复。
最佳答案
使用模式/匹配器/查找方法。 matches
将正则表达式应用于整个字符串。
Pattern pattern = Pattern.compile("[0-9]{2}%");
String test = "OAM-2 OMFUL abmasc01 and prdrot01 98% users NB in host nus918pe locked.";
Matcher matcher = pattern.matcher(test);
if(matcher.find()) {
System.out.println("Matched!");
}
关于Java 字符串正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19263788/