in reply to Regex matching next occurrence or to the end of line.

I may have misunderstood what you are asking for, but I think the solution to your problem is look-ahead assertions.

m< (?: # A char that is: [^\$] # Not a $ | # Or \$ (?! {= ) # A $ not followed by {= )+ # Many times >x;

Replies are listed 'Best First'.
Re^2: Regex matching next occurrence or to the end of line.
by nabeenj (Initiate) on Feb 04, 2015 at 18:03 UTC

    Many thanks for your response Eily. I have not used look-ahead assertions before. Useful stuff and it looks like what I need... I have had a reply from a colleague at work with a slight modification to the regex I was using. This works -

    if ( $string_exp =~ m/\Q$placeholder\E(.*?)((\$\{)|\z)/ ) { print "\"$1\"\n"; }

    This matches up to the next occurrence of the literal ${, otherwise to the end of the string.

    Thanks again.