Dlaczego moje wyrażenie na radzi sobie z pozbyciem się litery "a" z takiego tekstu: "a899.00";
private Double findNumberInString(String text) {
StringBuffer sBuffer = new StringBuffer();
Pattern p = Pattern.compile("[0-9]+.[0-9]*|[0-9]*.[0-9]+|[0-9]+");
Matcher m = p.matcher(text);
while (m.find()) {
sBuffer.append(m.group());
}
System.out.println(sBuffer);
return Double.parseDouble(sBuffer.toString());
}
Exception in thread "main" java.lang.NumberFormatException: For input string: "a899.00"
a899.00
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
at sun.misc.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
at java.lang.Double.parseDouble(Double.java:538)
at PhonesDownloader.findNumberInString(PhonesDownloader.java:126)
at PhonesDownloader.convertToList(PhonesDownloader.java:71)
at Main.main(Main.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)