How do I use regular expression to match the last character of a sentence?
38 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Adekunle Obasa
am 25 Feb. 2014
Kommentiert: Adekunle Obasa
am 26 Feb. 2014
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 Kommentare
Walter Roberson
am 25 Feb. 2014
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" .
Akzeptierte Antwort
Jacob Halbrooks
am 25 Feb. 2014
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, '.*(\.|!|?)$')
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Type Identification finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!