MATLAB: How to use regular expression to match the last character of a sentence

regular expression

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.

Best Answer

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, '.*(\.|!|?)$')