How do I use regular expression to match the last character of a sentence?

I want to use regular expression to match the last character of a sentence as ".", "!" or "?". A sentence that has any of these characters as the last character is to be copied into a file for further processing.

4 comentarios

Are there other symbols that act as delimiter between sentences?
Ans how are these sentences stored? In a single char array with delimiters? May be you can give a short example?
English can be ambiguous about where sentences end, in that it uses "." for abbreviations as well as for ending the sentence.
"Sing, Mr. Prefect, sing Row Row Row, etc., and dance as you do."
The "." after "Mr." does not end the sentence, and neither does the "." after "etc" .
Thanks all. The sentences have been determined. All those issues have been considered in getting out the sentences

Iniciar sesión para comentar.

 Respuesta aceptada

Here's a regular expression that might be helpful, which matches if the last character in the string is "." or "!" or "?".
>> candidate = 'Is this a sentence?';
>> regexp(candidate, '.*(\.|!|?)$')

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 25 de Feb. de 2014

Comentada:

el 26 de Feb. de 2014

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by