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.

  • 1. For each class there is documentation. Read. 2. Investigate the behavior of the code in the debugger. 3. Modify the code and see what changes. The following incomprehensible to you code you put it here too for analysis? - a_gura
  • Yes, I'll post it here for analysis. People need a rating, I need help. They help me, I increase their rating. - 111xbot111
  • about the question above: 1. need to study. and 2. no one forbids to spread anything here on the subject of what you cannot understand, if there was some sort in your words, then the answer must be sought in yourself - jcmax

1 answer 1

Method (do I call it correctly?) Pattern

class Pattern

Pattern.compile is, roughly speaking, a stencil of what we are looking for in a string (here are doubles).

compile itself is just a method, but in the arguments it really has a regular expression (or a template, although it is more correct to call it a regular expression)

You can read about regular expressions here (or in any Google issue of the corresponding request): http://en.wikibooks.org/wiki/%D0%A0%D0B5% D0% B3% D1% 83% D0% BB% D1% 8F% D1% 80% D0% BD% D1% 8B% D0% B5_% D0% B2% D1% 8B% D1% 80% D0% B0% D0% B6% D0% B5% D0% BD% D0% B8% D1% 8F

  • 2
    Specifically, this regularity is defined as: \ b - boundary, the word boundary \ d is a digit (or range 0-9) + is a quantifier indicating that the symbol is repeated 1 or more times. - any character except newline. Here, obviously, I meant just a period, but forgot to put the preceding escape slash. That is, the regularity is deciphered like this: word boundary / one or several numbers / any character / one or several numbers / word boundary - etki
  • Thank you very much for the help) - 111xbot111
  • @ 111xbot111, if the answer helped you, do not forget to mark it as correct. - Nofate