I need to cut up paragraphs into their constituent sentences. I also want to calculate with abreviations and decimals containing dots in the middle of the sentences.
My simplistic definition: A sentence starts with a capital letter, finishes with (.?!) followed by a space and the capital letter of the next sentence, plus something that is NOT (.?!)
I came up with the following negative look- ahead solution that works on decimals, but fails on abreviations.
The negative look-ahead should fail - and come back with true- till it arrives at the sentence ending position in my definition, but it doesn’t…
I would appreciate an explanaton for its failure.
Just after daybreak in Nags Head on the Outer Banks, about 200 miles northeast of Jacksonville, winds 85.43 miles / hour whipped heavy rain across the resort town. Tall waves covered what had been the beach, and the surf pushed as high as the backs of some of the N.Y. dt. houses and hotels fronting the strand. Lights flickered in one hotel, but the power was still on.
split on ‘.’
splits on every occurence of .,! or ? folowed by a space
Sorry, but I can’t find any better words for this than STUPID:mad:! Are there any sitepoint moderators at work here? And where is a link to report abuse?
I came here for professional advice, but there seems to be a need for a basic regexp lesson, instead!
First of all, simple alternation - (\.|\?|\!) - is stuff in round brackets where the characters need to be separated by the pipe sign (|). In square bracketted character classes, on the other hand, there are NO pipe signs, since alternation is IMPLICIT!
In alternation notice the need to escape metacharacters - characters with a special use in regexp.
The same special characters, or metacharacters do NOT need to be escaped in character classes - the stuff between square brackets, because ANY character there is taken literarely!! (There are special positions for a closing square bracket / negation / end of string mark etc but let’s leave them now…)
I left sitepoint forums years ago for these spammers and people who do not even bother to read a detailed description of a professional problem, but jot in their incompetent stuff like this!
By the way, do YOU know anything about look-arounds and things like atomic grouping?
Still waiting for expert help and an in-depth explanation for the failure of the regexp!