my $regex = '\b(' . join('|', @keywords) . ')\s((?:(?!(' . join('|', @keywords) . ')\b).)*)';
Rather than all the concatenation and the joins, you could take advantage of the double-quote-like behaviour of regexen by localising the list separator in a do block and interpolating @keywords.
my $regex = do { local $" = q{|}; qr{(?x) \b (@keywords) \s ( (?: (?! (@keywords) \b ) . )* ) } };
It looks a little clearer to my eye.
Cheers,
JohnGG
In reply to Re^2: parsing data pairs from single line
by johngg
in thread parsing data pairs from single line
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |