Reputation:
i would like to match recursively, all text that ends with :
or /
or ;
or ,
and remove all these characters, along with any spaces left behind, in the end of the text.
Example:
some text : ; , /
should become:
some text
What i have tried, just removes the first occurrence of any of these special characters found, how one can do this recursively, so as to delete all characters found that match? regex i use:
find: [ ,;:/]*
replace with nothing
Upvotes: 4
Views: 21482
Reputation: 27599
[ ,;:/]*$
should be what you need. This is the same as your current regex except with the $
on the end. The $
tells it that the match must happen at the end of the string.
Upvotes: 9
Reputation: 1480
You can use C#'s TrimEnd()
like so
string line = "some text : ; , / "
char[] charsToTrim = {',', ':', ';', ' ', '/'};
string trimmedLine = line.TrimEnd(charsToTrim);
Upvotes: 3