in reply to Applying a regex to part of a string

Your second way doesn't work if there's a bad match found before a good match can be found. You could embed some logic into the regex, but I'd really probably just use that first method of yours. Here's the steroid-enhanced way:
my ($START, $END) = (11, 30); if ($string =~ /^\C{$START,$END}?($pattern)(?(?{ $+[0] < $END })|(?!)) +/) { # it's ok }
It matches (in the test case) between 11 and 30 characters at the beginning of the string, and then tries matching the pattern. If, after it matches the pattern, $+[0] is still less than $END, then it succeeds; otherwise, it backtracks.

Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart

Replies are listed 'Best First'.
Re^2: Applying a regex to part of a string
by holdyourhorses (Monk) on Aug 19, 2005 at 07:27 UTC

    This is something I need to study more thoroughly. At the moment, I am not sure I fully understand the details of what you propose, although I can see how it works in principle.

    Thanks