in reply to Parse for a list in a long string
#! /usr/bin/perl use warnings; use strict; my $element = qr/(?: \w+ (?: \s+ is \s+ \w+ )? )/x; while (<DATA>) { chomp; s/\s+/ /g; while (/\b test\s+ ( $element (?: , \s* $element )* )/xg) { my $match = $1; my @elements = split /\s*,\s*/, $match; shift @elements; s/\s+ is \s+ \w+//x for @elements; print "($_)" for @elements; print "\n"; } } __DATA__ this line has nothing, nothing, nothing... 1 , 2, 3, 4 is four, 5, 6 test 00,11 is one,22, 33 is three,44,55 is + the best, and this is not a test 111, 222, 333 as random words to + finish this should be a test, but nothing must be returned 4444, 7777, 9999 i +s garbage
|
|---|