tags:

views:

95

answers:

1

I have the following Regexp :

regexp=/(\w+) \s* : \s* (\w+) \s+ (.*) \s* ;?/ix

And I am trying to get the captures:

names, direction, type = iotext.match(regexp).captures

This works fine for a single "x : in integer;" ,

but how could I also get all the groups of other match data in my file :

"x : in integer;
y : in logic;
z : in float;"
+1  A: 

Your regex regexp is ok, it just only matches one occurance. If you want to match every occurance try

"x : in integer; y : in logic; z : in float;".scan(regexp)

which results in an array with 3 elements containing an array of each 3 matches, i.e.

 [ ["x", "in", "integer"], ["y", "in", "logic"], ["z", "in", "float"] ]
Peter Kofler
So simple. Thanks a lot.
JCLL