sinDizzy
sinDizzy

Reputation: 1364

Match repeated groups after keyword using regex

VB2010 Using regex I cant seem to get this seemingly easy regex to work. I first look for a line with a keyword TRIPS that has my data and then from that line I want to extract repeated groups of data made up of an alpha code and then a number.

MODES       1       0       0  
OVERH   X  28   H   0   Z 198  
TRIPS   X  23   D   1   Z 198  
ITEMSQ      1       0       0  
COSTU   P  16   E 180  
CALLS       0       0 

I have

^TRIPS   (?<grp>[A-Z]\s{1,4}\d{1,3}) 

Which gives me one match and the first group "X 23". So I extend it by allowing it to match up to 4 groups.

^TRIPS   (?<grp>[A-Z]\s{1,4}\d{1,3}){0,4}

but I get one match with still only one group.

Upvotes: 1

Views: 48

Answers (1)

Steven Doggart
Steven Doggart

Reputation: 43743

You aren't allowing for white space between the groups. You need to do something like this:

^TRIPS   ((?<grp>[A-Z]\s{1,4}\d{1,3})\s+){0,4}

Upvotes: 1

Related Questions