for (int i = 0; i < s.length; i++) { Pattern pt = Pattern.compile("\\b\\d+.\\d+\\b"); Matcher matcher = pt.matcher(s[i]); while (matcher.find()) { res[i] = matcher.group(); } }
This is how I understood: an array is started that checks every line of the s[i]
array. Method (do I call it correctly?) Pattern
searches in the i-th line. Pattern.compile
is, roughly speaking, a stencil of what we are looking for in a string (here are double
). pt.matcher(s[i])
compares the string with the stencil (?), and while (matcher.find()) {res[i] = matcher.group();}
- as long as there are matches (i.e., found so far, writing to the res[i]
array). I didn’t understand at all how the stencil works: \\b\\d+.\\d+\\b
Explain what is not said, please.