in reply to How to clean an array of strings after a split

You could also search the pieces of interest with a single regex, and fill the array with sufficiently many empty strings like this:

my ($var1, $var2, $var3, $var4, $var5) = ( $str =~ /(?:^|\|)\s*(.*?)\s +*(?=$|\|)/g, ("")x5 );

Replies are listed 'Best First'.
Re^2: How to clean an array of strings after a split
by MrSnrub (Beadle) on Aug 29, 2013 at 14:21 UTC
    Thanks, but please explain what this does: (?:^|\|) and this: (?=$|\|)
      (?: non-capturing parentheses ^ start of string | or \| pipe character )
      (?= look-ahead, not part of match $ end of string | or \| pipe character )

      So I am looking for something between the start of string or a pipe and a pipe or the end of the string, ignoring whitespace, matching non-greedily. In order to make it work, I need to use each pipe twice, once for the string before the pipe, and then for the string following it. Thus the look-ahead assertion. HTH.