in reply to How do I match lines of UP TO 40 chars BUT NO MORE in a block of text?
My reply at Re: How do I match lines of 40 characters long in a block of text? does what you want I think. Note that you don't really want to match 0 lines unless you want everything to match. Also, when you are constructing a regex, it is best to be able to state exactly what you want. I think you really want "1 to 4 lines each consisting of 0 to 40 characters followed by a newline." I've included the code from original reply below for your convenience.
/ ( # 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.";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: How do I match lines of UP TO 40 chars BUT NO MORE in a block of text?
by kleinbiker7 (Sexton) on Sep 25, 2002 at 21:21 UTC | |
by sauoq (Abbot) on Sep 25, 2002 at 21:33 UTC | |
by Anonymous Monk on Sep 26, 2002 at 01:57 UTC | |
by sauoq (Abbot) on Sep 26, 2002 at 02:11 UTC | |
by kleinbiker7 (Sexton) on Sep 26, 2002 at 15:06 UTC |