in reply to Re: Re3: Regex: get first N characters but break at whitespace
in thread Regex: get first N characters but break at whitespace
The thing is, it doesn't matter how fast you are if you are giving the incorrect result. I was taking into account that a paragraph would have a newline on the end of each line.
This can be easily incorporated into the regex approaches. The problem so far is that .* doesn't match a newline. If you want that just add the /s modifier:
timethese(-3, { Hofmator => '($chunk) = substr($string,0,201) =~ /(.*\S)\s/s', japhy => '($chunk) = $string =~ /^(.{1,200})(?<!\s)(?!\w)/s;', tye => '($chunk) = $string =~ /^(.{0,199}\S)\s/s', });
-- Hofmator
|
|---|