How to stop the matching when end of line (Ruby2.0.0)

I want to scan a text composed of lines. When I recognize a keyword I am
using a regex for this type of line. When I recognize another type of
keyword I am using another regex, etc.

Example: my text

Function0 foo=‘hello’
Function1 parameter1 value1, parameter2 value2 , … , parameterN valueN
Function2 12.34 56.78

When I recognize the keyword “Function1”, I am using this regex:

/(?:(\w+) +|(?!^)\G) *(\S+ +[^\n, ]+) *,?/i

I am using this code to scan the line:

while mytext =~ /…/ do
case $2 #$1 = the keyword
when ‘parameter1 value1’

end #case
$’ #next part of the line
end #while

The first match returns $1 = Function1 $2 = parameter1 value1 which is
The second match doesn’t return $1 = Function2 $2 = parameter2 value2

First question: dows my code correct for scanning the line ?
Second question: why I cannot match couples parameterX value X ?
Third question is: how to stop when the end of line is found ?

I tried this but not better:
/(?:(\w+)(\s+)|\G(?<!^)) (\S+\s+\S+)\s,?/i

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs