in reply to Re: Regex : Return match elements
in thread Regex : Return match elements

first I also think for split but I am loosing '&' '|' while spliting. But you did the magic. thanks

Replies are listed 'Best First'.
Re^3: Regex : Return match elements
by Marshall (Canon) on Jun 24, 2016 at 14:45 UTC
    Split uses a regex (regular expression) to decide when to create elements of the resulting array. The code uses & or | to decide when to "make a new array element". Normally, in most splits, it is desired to "throw away" the split characters. Classic is: split /\s+/, $line; to parse space separated tokens. The use of a capture group in the regex allows the "splitted upon tokens" to appear in the output. This is an unusual situation, but works here.