in reply to Truncating Last Sentence

Fantastic - several ways to solve my problem (I forgot about RIndex)!

I have decided to use: $lRow =~ s/\.[^.]+$/./;

Let me try to decode the RegEx:

Look for a period followed by OPTIONAL number of non-period characters followed by the EOL char. Substitue all of these with a single period.

The [^.] solves the greedy problem by making sure there is some non-period characters between things. Thanks!

Replies are listed 'Best First'.
Re: Re: Truncating Last Sentence
by Belgarion (Chaplain) on May 14, 2004 at 21:15 UTC

    Actually, s/\.[^.]+$/./; says to match a period followed by one or more non-periods anchored at the end of a line. See perlre for more information.

Re: Re: Truncating Last Sentence
by paulbort (Hermit) on May 17, 2004 at 18:19 UTC
    Isn't this going to break horribly if the sentence being discarded is about the band Mr. Mister? Or the Orbital song "Dr. Who"? Maybe Lingua::EN::Sentences would help. From the POD:

    The Lingua::EN::Sentence module contains the function get_sentences, which splits text into its constituent sentences, based on a regular expression and a list of abbreviations (built in and given).

    Certain well know exceptions, such as abreviations, may cause incorrect segmentations. But some of them are already integrated into this code and are being taken care of. Still, if you see that there are words causing the get_sentences() to fail, you can add those to the module, so it notices them.

    --
    Spring: Forces, Coiled Again!