in reply to How do I match lines of UP TO 40 chars BUT NO MORE in a block of text?
In your prior post, lower processing time was the goal, not an artificial avoidance of loops not generated within the regex engine. See my reply Re: How do I match lines of 40 characters long in a block of text? for an efficient loop.
Accepting that this is homework or a bar bet; if you must use a regex to decide that a block of text has fewer than five short lines, try to match five or more - failure is success:
if ($foo !~ m/\A(?: #anchor start and group (?:.{41,}\n)* #maybe some long lines (?:.{0,40}\n) #one short line ){5,} #five or more (?:.{41,}\n)* #maybe some more long lines \z #anchor end /x ) { #do something }
Update: Fixed link. Your first regex may work if you anchor the ends. It is matching long lines by backtracking to the -40 position from the newline.
After Compline,
Zaxo
|
|---|