I'm trying to split text out that is contained between a set of brackets [].
I tried to place both variables inside the $split variable, but it would only recognize one of the brackets. I came up with this option, which works:
and produces:
before
within
after
but I wanted to know if there is a way to combine the two bracket search terms into one variable.
thanks
I tried to place both variables inside the $split variable, but it would only recognize one of the brackets. I came up with this option, which works:
Code:
$line1 = 'before[within]after';
$split= ('\[');
$split2 = ('\]');
@values = split(/$split|$split2/,$line1);
foreach $val (@values) {
print "$val\n";
};
before
within
after
but I wanted to know if there is a way to combine the two bracket search terms into one variable.
thanks