Q:

Parse file, find a string and store next values

I need to parse a file according to different rules.
The file contains several lines. 
I go through the file line by line. When I find a specific string, I have to store the data present in the next lines until a specific character is found.
Example of file:
start {
  /* add comment */
  first_step {
     sub_first_step {
     };
     sub_second_step {
        code = 50,
        post = xxx (aaaaaa,
                    bbbbbb,
                    cccccc,
                    eeeeee),
        number = yyyy (fffffff,
                       gggggg,
                       jjjjjjj,
                       ppppppp),
     };

So, in this case:
 File.open(@file_to_convert, "r").each_line do |line|

In "line" I have my current line. I need to:
1) find when the line contains the string "xxx"
if line.include?("union") then 

Correct?
2) store the next values (e.g.: aaaa, bbbb, ccccc,eeee) in an array until I find the character ")". This highlights that the section is finished.
I think we I reach the line with the string "xxxx" I have to iterate the next lines inside the block "if".

A:

Try this:
file_contents = File.read(@file_to_convert)

lines = file_contents[/xxx \(([^)]+)\)/, 1].split
# => ["aaaaaa,", "bbbbbb,", "cccccc,", "eeeeee"]

The regex (xxx \(([^)]+)\)) takes all the text after xxx ( until the next ), and split splits it into its items.

