Regexp: how to get each matchdata group?

I have the following regexp:

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

And I'm trying to get a capture:

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

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

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

 "x : in integer; y : in logic; z : in float;" 
+4
source share
1 answer

Your regexp regex is fine, it just matches only one event. If you want a match for any situation, try

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

which leads to an array with 3 elements containing an array of every 3 matches, i.e.

  [ ["x", "in", "integer"], ["y", "in", "logic"], ["z", "in", "float"] ] 
+3
source

All Articles