#!/usr/bin/perl -w use strict; use Regexp::Common; my $text = <'{}'}//g; print $text; #### our $re = qr/(?:\{(?:(?>[^\{\}]+)|(??{$re}))*\})/; #### use YAPE::Regex::Explain; print YAPE::Regex::Explain->new($re)->explain; #### The regular expression: (?-imsx:(?:\{(?:(?>[^\{\}]+)|(??{$re}))*\})) matches as follows: NODE EXPLANATION ---------------------------------------------------------------------- (?-imsx: group, but do not capture (case-sensitive) (with ^ and $ matching normally) (with . not matching \n) (matching whitespace and # normally): ---------------------------------------------------------------------- (?: group, but do not capture: ---------------------------------------------------------------------- \{ '{' ---------------------------------------------------------------------- (?: group, but do not capture (0 or more times (matching the most amount possible)): ---------------------------------------------------------------------- (?> match (and do not backtrack afterwards): ---------------------------------------------------------------------- [^\{\}]+ any character except: '\{', '\}' (1 or more times (matching the most amount possible)) ---------------------------------------------------------------------- ) end of look-ahead ---------------------------------------------------------------------- | OR ---------------------------------------------------------------------- (??{$re}) run this block of Perl code (that isn't interpolated until RIGHT NOW) ---------------------------------------------------------------------- )* end of grouping ---------------------------------------------------------------------- \} '}' ---------------------------------------------------------------------- ) end of grouping ---------------------------------------------------------------------- ) end of grouping ----------------------------------------------------------------------