Pattern pattern = Pattern.compile("v(\\d\\.\\d)");
String s = "<a href>asldkjaskldj<>kljlaksjd v1.3<asdas>";
System.out.println(pattern.matcher(s).group());
为什么这种模式与1.3不匹配?
答案 0 :(得分:2)
这对我有用:
Pattern pattern = Pattern.compile("v(\\d\\.\\d)");
String s = "<a href>asldkjaskldj<>kljlaksjd v1.3<asdas>";
Matcher matcher = pattern.matcher(s);
matcher.find();
System.out.println(matcher.group());
匹配v1.3。
在您尝试find
之前,group
不会向您提供结果
答案 1 :(得分:1)
我试过这个,它对我有用。
String s = "<a href>asldkjaskldj<>kljlaksjd v1.3<asdas>";
Pattern pattern = Pattern.compile("v(\\d\\.\\d)");
Matcher m = pattern.matcher(s);
if(m.find()){
System.out.println("matches");
}else{
System.out.println("no match");
}