diotalevi has asked for the wisdom of the Perl Monks concerning the following question:
Given data like "a[b[c[d]]" the following regex matches the inner-most [d]. I'd like suggestions on how I can match the outermost [c[d]]. I feel like there's something simple I'm missing but ... well, I'm missing it.
my $re; $re = qr/ \[ # Opening bracket ( # Capture the contents [^][]+ # Body of a link | (??{$re}) # Or recurse ) \] # Closing bracket /x; $k = "a[b[c[d]]"; $k =~ s/$re/<$1>/g; print $k;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Maximal match in a recursive regex ([^][]+)
by tye (Sage) on Jun 26, 2003 at 18:26 UTC | |
by diotalevi (Canon) on Jun 26, 2003 at 18:29 UTC | |
|
Re: Maximal match in a recursive regex
by diotalevi (Canon) on Jun 26, 2003 at 17:06 UTC | |
by Mr. Muskrat (Canon) on Jun 26, 2003 at 17:35 UTC |