How do I use regular expression to match the last character of a sentence?
34 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2014-2-25
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" .
采纳的回答
Jacob Halbrooks
2014-2-25
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Identification 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!