I am attempting to remove all trailing white-space and periods from a string so that if I took either of the following examples:
var string = " .. bob is a string .";
var string = " . bob is a string . ..";
They would end up as:
"bob is a string"
I know diddly squat about regex but I found a function to remove trailing white-space here:
I tried modifying to include periods however it still only removes trailing white-space characters:
Can anyone tell me how this is done and perhaps explain the regular expression used to me?
Your regex is almost right, you just need to put the quantifier (+) outside of the character class ():
var str = " . bob is a string . .."; str.replace(/^[.\s]+|[.\s]+$/g, ""); //"bob is a string"