以下のような文字列があるとします
String s1 = "This is a new direction. Address located. \n\n\n 0.35 miles from location";
今、「場所から 0.35 マイル」のみを抽出したいと考えています。この数値を他の数値と比較するには、「0.35」にもっと興味があります。
文字列 s1 は、次のパターンの場合もあります。
String s1 = "This is not a new direction. Address is not located. \n\n\n 10.25 miles from location";
また
String s1 = "This is not a new direction. Address is located. \n\n\n 11.3 miles from location";
Plsは私が結果を達成するのを助けます. ありがとう!
私はこれを試しました
String wholeText = texts.get(i).getText();
if(wholeText.length() > 1) {
Pattern pattern = Pattern.compile("[0-9].[0-9][0-9] miles from location");
Matcher matcg = pattern.matcher(wholeText);
if (match.find()) {
System.out.println(match.group(1));
}
でも、xx.xxマイルだとどうしたらいいのかわからない…