This really isn't as hard as everyone has made it out to be. You almost had it, but you need to anchor so as not to match partial lines. You also probably want to avoid matching the empty string. I'm guessing that you really want "1 to 4 lines each consisting of up to 40 characters followed by a newline."
/ ( # Assuming you want capture these lines. (?: # Group each line. ^ # Beginning of the line. .{0,40}\n # 0 to 40 characters followed by a newline. ){1,4} # 1 to 4 lines. (0 will permit an empty match.) ) # Done capturing. /mx; # /m so that ^ anchor works, /x for comments.
-sauoq "My two cents aren't worth a dime.";
In reply to Re: How do I match lines of 40 characters long in a block of text?
by sauoq
in thread How do I match lines of 40 characters long in a block of text?
by kleinbiker7
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |