On Fri, 2008-10-03 at 11:52 +0300, Vyacheslav Karamov wrote:
> Hi All!
>
> I need to capture something in braces using regular expressions.
> But I don't need to capture wrong data:
>
> [Some text] - correct
> (Some text) - also correct
> [Some text) - wrong
> (Some text] - also wrong
>
#!/usr/bin/perl
use strict;
use warnings;
while( <> ){
chomp;
while( /\((.*?)\)|\[(.*?)\]/g ){
my $result = $1;
$result = $2 unless defined $result;
print "$result\n";
}
}
__END__
Note that if these structures can be nested, you will have to use a FSA
with a push-down stack.
--
Just my 0.00000002 million dollars worth,
Shawn
Linux is obsolete.
-- Andrew Tanenbaum
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/