If you simply want to append a "s" to the string, just use newstring = oldstring + "s"
.
If you need to add the s before the punctuation characters at the end of the sentence, you could search for (?=\W+$)
and replace that with s
. I can provide a code snippet if you say which language you're using. However, this assumes punctuation to be present (it won't match if the strings ends in an alphanumeric character).
In VB.net, for example:
ResultString = Regex.Replace(SubjectString, "(?=\W+$)", "s")
If you need to add an "s" at the end of the string, before any punctuation if present, then you can search for (?=\W+$)|(?<!\W)$
and replace with s
.
As an annotated multiline regex:
(?=\W+$) # match a position before one or more non-word characters at the end of the string
| # or
(?<!\W)$ # match the position at the end of the string unless it's preceded by a non-word character
If you need to do something else, please rephrase your question and give some examples.