Re: how to remove blocks between nested brackets
- From: "John W. Krahn" <someone@xxxxxxxxxxx>
- Date: Thu, 31 Jan 2008 13:08:46 GMT
Si wrote:
Beeing new to perl and not wanting to learn using it like assembler, I need to delete parts of a single line (possibly long) that are enclosed between nested brackets:
abcd efgh [ij: 123-[456]-klm; nop-789]; qrst; uvw [xyz: 98-76-[ef]; gh; ijkl] (mnop)
The comments between [] must be discarded to split with ';' delimiter.
The expected result is:
array[0] == "abcd efgh"
array[1] == "qrst"
array[2] == "uvw (mnop)"
$ perl -le'
my $line = q{abcd efgh [ij: 123-[456]-klm; nop-789]; qrst; uvw [xyz: 98-76-[ef]; gh; ijkl] (mnop)};
1 while $line =~ s/\[[^][]*]//g;
my @array = split /\s*;\s*/, $line;
print qq["$_"] for @array;
'
"abcd efgh"
"qrst"
"uvw (mnop)"
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
.
- References:
- Prev by Date: how to remove blocks between nested brackets
- Next by Date: Re: How would I create a Regular Expression to check
- Previous by thread: how to remove blocks between nested brackets
- Next by thread: Re: how to remove blocks between nested brackets
- Index(es):