we have the string: \ r \ n \ t \ t \ t \ t $ 6.32 Save $ 1.33 instantly \ r \ n
the following regular expression: ([\ d.,] +) returns only the first digits (6.32), who can answer why this happens? In theory, he should return both numbers

  • one
    Why should he return two groups? On this sample text, the expression matches exactly what it returns. In the loop, do a sequential iteration, as in java: while (matcher.match ()) {... work with a match} Or, if there is an analogue of preg_match_all from php, use it. PS I am not good at Ruby, but since for a long time nobody answers, I give general advice. - ReinRaus

2 answers 2

Not at all clear, do you want to get output 6.32 and 1.33 or what? Then you need to do this, and no groups are needed:

 "\r\n\t\t\t\t$6.32Save $1.33 instantly\r\n".scan /\d+\.\d+/ 

    Try using the scan method:

     "\r\n\t\t\t\t$6.32Save $1.33 instantly\r\n".scan /([\d.,]+)/ => [["6.32"], ["1.33"]] 

    I just checked it in irb - your regular expression ([\d.,]+) Normally returns both numbers.