If you want to extract all Int and Float from String , you can follow my solution:
private ArrayList<String> parseIntsAndFloats(String raw) { ArrayList<String> listBuffer = new ArrayList<String>(); Pattern p = Pattern.compile("[0-9]*\\.?[0-9]+"); Matcher m = p.matcher(raw); while (m.find()) { listBuffer.add(m.group()); } return listBuffer; }
If you want to analyze negative values as well, can you add [-]? into the template as follows:
Pattern p = Pattern.compile("[-]?[0-9]*\\.?[0-9]+");
And if you also want to set , as a separator , you can add ,? into the template as follows:
Pattern p = Pattern.compile("[-]?[0-9]*\\.?,?[0-9]+");
.
To check the patterns, you can use this online tool: http://gskinner.com/RegExr/
Note. For this tool, remember unescape if you are trying to use my examples (you just need to remove one of \ )
source share