I would like to strip all of the the punctuations (except the dot) from the beginning and end of a string, but not in the middle of it.
For instance for an original string:
@#%%.Hol$a.A.$%
I would like to get the word .Hol$a.A.
removed from the end and beginning but not from the middle of the word.
Another example could be for the string:
@#%%...&Hol$a.A....$%
In this case the returned string should be ..&Hol$a.A....
because we do not care if the allowed characters are repeated.
The idea is to remove all of the punctuations( except the dot ) just at the beginning and end of the word. A word is defined as \w
and/or a .
A practical example is the string 'Barnes&Nobles'
. For text analysis is important to recognize Barnes&Nobles
as a single entity, but without the '
How to accomplish the goal using Regex?