in reply to Re: Re: How do I match lines of 40 characters long in a block of text?
in thread How do I match lines of 40 characters long in a block of text?

I'm still curious why he would want to match zero lines. I'd expect him to want to match at least one line.

And: as soon as you ask for at least one line, without an "^" anchor, your first line might contain more than 40 characters, only the regex it will only grab the last 40 ones of that line!

In short: it is definitely not a bad idea to add an anchor.

/^((?:.{0,40}\n){0,4})/;
or
/^((?:.{0,40}\n){1,4})/m;
The latter case can grab 1 to 4 whole lines anywhere in your text.

Replies are listed 'Best First'.
Re: Re: Re: Re: How do I match lines of 40 characters long in a block of text?
by BrowserUk (Patriarch) on Sep 25, 2002 at 21:26 UTC

    Agreed bart, I'm not sure that the OP has clearly stated his req's or perhaps he doesn't have a clear picture of what his req's are.

    I agree with you about the need for anchors, but despite using either /m or /s, I couldn't get things to work with just that. I ended up using \A which worked better, but on its own didn't seem to be enough. I also played with using $, \Z and \z, but I admit I am still a little confused about quite what each does in the contexts of /s and /m. Something I need to play with more.


    Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!