Hey there! I'm currently working on a project that requires extracting sentences from a paragraph using regex in JavaScript. Unfortunately, my attempts to achieve this have resulted in syntax errors as I have tried methods used in other programming languages. I want the regex to not consider titles (like Mr., Mrs., etc.) as the end of sentences and to be sensitive to strings like "Michael G." so it won't interpret them as sentence endings. Below is the snippet of code with the regex pattern I've been working with. Despite trying multiple approaches, I still haven't been successful in getting it to work. Any assistance on this matter would be greatly appreciated.
var sentences = $(this).text()
.replace(/(((?![.!?]['".”]?\s).)*[.!?]['".”]?)(\s|$)/g,
'<span class="sentence"> $1 </span> $3<div class="commentform">' + formdialog + '</div>');
The paragraph from which sentences need to be extracted:
“He is trying to give a push,” said a senior American official, who spoke on the condition of anonymity because of the delicacy of the matter, adding that the talks were bogging down “both because of short-term irritants and slowness at getting at fundamental issues.” Mr. Kerry was a tireless prod and a frequent presence in Jerusalem and Ramallah leading up to the resumption of talks in July, and he has recently met for hours at a time with Prime Minister Benjamin Netanyahu of Israel and the Palestinian Authority president, Mahmoud Abbas, in neutral sites like New York, London and Rome. Now, after a brief period of dealing with other problems, he is returning to the region to throw himself back into the process.
Reporting from Riyadh, Saudi Arabia, Michael R. Gordon contributed to this report.