in reply to regexp word break help
Seems a little redundant I suppose, but I did it off the top of my head.$str = "make sure this string is less than 45 chars and truncate on wh +itespace if need be"; $fstr = substr($str,0,45); $sstr = substr($str,45); $fstr =~ s/\s+\w*$// if $sstr =~ /^\w/;
UPDATE: I benchmarked it and it seems to compare favorably to graff's first option which I figured would be fastest since it doesn't use regexes at all.
|
|---|