#!/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";
In reply to Re: Regex for outside of brackets
by tybalt89
in thread Regex for outside of brackets
by theravadamonk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |