There are somes things that aren't clear : does the number belong to data, or is it another information ?
Here, I've considered that numbers before the STRUCT keyword and data are not the same. Plus I've taken into account the fact that data may contains numbers. What make these numbers different is that they do not precede a STRUCT keyword.
To sum up the proposed solution to your problem : match everything and then remove what you are not interested in.
# Text wrapped to fit in the screen my $text = "0011222STRUCTdata..........6ab.." . "02121STRUCTdata.........." . "021232STRUCTdata......" . "02342STRUCTdata......"; my @matches = $text =~ m/(\d+) # First match some numbers STRUCT # Then the STRUCT keyword (.+?) # Then the data, that have to # be followed by (?= # (look-ahead assertion) (?:\d+STRUCT # - numbers and 'STRUCT' | # or $ # - end of line ) )/xg; # Then remove the first two matches that is first numbers and # first data @matches = splice @matches, 2; { local $, = ","; print @matches, "\n"; }
The look ahead trick helps to easily manage numbers in the data text.
In reply to Re: Pattern Matching request
by zejames
in thread Pattern Matching request
by Novice_1
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |