ensnare
ensnare

Reputation: 42023

How can I remove all trailing dashes from a string?

Example:

string1 = 'title--'
string2 = 'title-'
string3 = 'this-is-a-title----'

>> print doSomething(string1)
>> title

>> print doSomething(string2)
>> title

>> print doSomething(string3)
>> this-is-a-title

Upvotes: 3

Views: 2334

Answers (1)

Sven Marnach
Sven Marnach

Reputation: 601471

string1.rstrip("-")
# "title"
string2.rstrip("-")
# "title"
string3.rstrip("-")
# "title-is-a-title"

Upvotes: 10

Related Questions