in reply to Re: Smart Substrings
in thread Smart Substrings

you know,

I *did* think of that, but was happier giving a 3 line solution :)

I used a similar regex in one of my scripts to split a line as close to 70 chars as possible without breaking in a word). To avoid the problem you suggest, I would use this:

unless ($string =~ s/^(.{6,12})\b\s.*/$1.../gi)
But for such a small string it's a little rough. The context I use it in is {50,70} for line breaks, and that seems to work just fine.

I think the *idea* is sound though, and I'm sure the user could amend .{0,12} to .{4,12} or .{7,12} depending on their specific requirements to get it to work for them.

cLive ;-)