in reply to Regex for outside of brackets
#!/usr/bin/perl # https://perlmonks.org/?node_id=1218434 use strict; use warnings; my $string = 'THIS IS OUTSIDE (THIS IS INSIDE)'; my $inside = 0; # true if inside parens my $onlyoutside = $string =~ s/ (\() | (\)) | ([^()]+) / $1 ? $inside++ x 0 : $2 ? $inside-- x 0 : $3 x !$inside /gexr; print "before <$string>\n after <$onlyoutside>\n";
|
|---|