in reply to Need help with regex to replace 4th \s with \n in data line

It might be better not to count the spaces, but the characters, which will be a better guess for the actual line length. You can wrap any string to a specified minimum and maximum chars per line (here:{3,30}) with that regex:

$_ = 'School of Wisdom and Knowledge College Preparatory'; s/(.{3,30})\s+(.+?)/$1\n$2/g; print;

~Django
"Why don't we ever challenge the spherical earth theory?"

Replies are listed 'Best First'.
Re: Re: Need help with regex to replace 4th \s with \n in data line
by Popcorn Dave (Abbot) on Sep 06, 2002 at 05:11 UTC
    Actually you're right in that thinking. After looking at some of my data, I realized that the 4 space theory is going to blow up on a name like John F. Kennedy Middle School - which I believe is small enough to fit on the label.

    I had been working out in my head how to go about checking actual string length and make the decision then, but your solution is excellent! ++!

    Some people fall from grace. I prefer a running start...