As a general technique, here's a way to emulate  [^set] where you are dealing with a potentially complex regex expression rather than a simple character class:

c:\@Work\Perl\monks>perl -wMstrict -le "my $cd = qr{ cd }xms; my $not_cd = qr{ (?! $cd) . }xms; ;; for my $s (',abcdefg,pqrstuv', ',abefg,pqrstuv', @ARGV) { my $t = $s; print qq{'$t'}; $t =~ s{ , $not_cd* ($cd?) [^,]* , }{=$1=}xms; print qq{'$t' \n}; } " ',abcdefg,pqrstuv' '=cd=pqrstuv' ',abefg,pqrstuv' '==pqrstuv'
Where:
  $cd is an arbitrary regex pattern;
  $not_cd matches any character that does not begin the arbitrary pattern.

Update: Here's an example more in tune with your OPed assertion that the start and end delimiter patterns (and the optional included pattern) may be complex:

c:\@Work\Perl>perl -wMstrict -le "my $maybe = qr{ cd? }xms; ;; my $start = qr{ A | BC | DE?F }xms; my $end = qr{ U | VW | XY?Z }xms; my $excluded = qr{ (?! $end | $maybe) . }xms; ;; for my $s ('AxxcdxxVWABCDEFUVWXYZ', 'BCxxxUABCDEFUVWXYZ', @ARGV) { my $t = $s; print qq{'$t'}; $t =~ s{ $start $excluded* ($maybe?) .*? $end }{=$1=}xms; print qq{'$t' \n}; } " BCxxcxxXZABCDEFUVWXYZ 'AxxcdxxVWABCDEFUVWXYZ' '=cd=ABCDEFUVWXYZ' 'BCxxxUABCDEFUVWXYZ' '==ABCDEFUVWXYZ' 'BCxxcxxXZABCDEFUVWXYZ' '=c=ABCDEFUVWXYZ'
The  .*? $end could be  $excluded* $end instead. This would make the regex perhaps a bit more robust, but a bit slower.


Give a man a fish:  <%-(-(-(-<


In reply to Re: greedy subexpression between two nongreedy ones by AnomalousMonk
in thread greedy subexpression between two nongreedy ones by raygun

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.