Sometimes it's better to extract out what you want rather than trying to split out what you don't want. (\K available with Perl 5.10+.)
>perl -wMstrict -le "my $str = 'Iteration {Applied Field} {Total Energy} {Foo} { a b + c d } Mx'; ;; my $rx_word = qr{ [[:alnum:]]+ }xms; my $rx_curly = qr{ { \s* \K $rx_word (?: \s+ $rx_word)* (?= \s* }) +}xms; ;; my @fields = $str =~ m{ $rx_curly | $rx_word }xmsg; printf qq{'$_' } for @fields; " 'Iteration' 'Applied Field' 'Total Energy' 'Foo' 'a b c d' 'Mx'
In reply to Re: Splitting string using two overlapping patterns
by AnomalousMonk
in thread Splitting string using two overlapping patterns
by kpr
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |