getting numbers from lines of text

Posted by Flethuseo on Stack Overflow See other posts from Stack Overflow or by Flethuseo
Published on 2011-02-27T23:21:11Z Indexed on 2011/02/27 23:25 UTC
Read the original article Hit count: 230

Filed under:

Hi everyone, I want to parse a text file, where I get numbers that are between parenthesis like this:

1 2 3 (4 - 7) 8 9
1 3 8 (7 - 8) 2 1
1 2 (8 - 10) 3 2

should return an array for each:

array1:
4
7
8

array2:
7
8
10

I am thinking of using split for each line, like line.split("("), but that doesn't quite doing the trick.. I was wondering if there is something more sophisticated for the job.

Any help appreciated,

Ted

© Stack Overflow or respective owner

Related posts about ruby