I am wondering, in the context of a computer processing text, which characters or combination of characters can end an English sentence. A question mark, exclamation mark and period are the most obvious, but are there any others? What if the final character is a parenthesis?
I am working on a computer program that produces a document, and in the document I am displaying some user-entered text in the form of a sentence. This user text ends the sentence, so I need to ensure there's a full stop before the next sentence begins.
I could simply add a period to the end of the text, which would work most of the time:
This is an example►
This is an example.
But of course if the user entered text that includes an end-of-sentence marker, this simple solution won't work:
So clearly if the last character is an exclamation mark, question mark or period, then no extra period should be appended.
However it doesn't seem so simple. What if the last character is a closing parenthesis? You could simply add a period to
(Example) and it would be fine, but if it's
(Example.) then you should not add a period as
(Example.). is not correct.
So in this case it seems you need to check the last two characters to see if the sentence has ended.
But then what if the sentence ends with a quotation mark?
Please refer to the song "Sweet Dreams (Are Made of This)"
So it seems you have to check the final three characters to see whether the sentence has ended, and whether you should append a period or not.
Is there any rule (suitable for implementation in a computer program) that would cover at least the majority of cases? I am thinking something like:
- Check the last character
- If it is
.then the sentence has ended
- If it is
)then drop the character from the end and go back to 1
- Otherwise the sentence has not ended, and a period should be appended to the original text.
Would this work, or does it miss other combinations that might occur?
Out of curiosity, what other character combinations might there be that could potentially end a sentence, but require closer scrutiny rather than blindly appending a full stop?