|XP is just a number|
Truncating Last Sentenceby FatDog (Beadle)
|on May 14, 2004 at 19:28 UTC||Need Help??|
FatDog has asked for the wisdom of the Perl Monks concerning the following question:
How do I truncate the last/partial fragment of a sentance from a paragraph? (strip all the characters after the last "." in the string)?
I have several million long-text descriptions that I need to truncate to 1000 characters. This often leaves me with a block of text that looks like:
"...one of his best tracks. It's good. His other notew"
I want to identify these fragments and remove the partial sentence or all chars past the last period to get this:
"...one of his best tracks. It's good."
I have used "Split" to create an array based on "." chars, then truncated the last member off and re-joined but this adds a 20 fold increase in processing time.
I also know I have to be careful of greedy pattern matching but I am un-sure how to use the non-greedy "+?" regreps.