フィルターのクリア

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

18 ビュー (過去 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
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" .
Adekunle Obasa
Adekunle Obasa 2014 年 2 月 26 日
Thanks all. The sentences have been determined. All those issues have been considered in getting out the sentences

サインインしてコメントする。

採用された回答

Jacob Halbrooks
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 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by